define(['browser'], function (browser) { var supportsTextTracks; var hlsPlayer; var requiresSettingStartTimeOnStart; var subtitleTrackIndexToSetOnPlaying; var currentTrackList; var currentPlayOptions; function htmlMediaRenderer(options) { var mediaElement; var self = this; function onEnded() { destroyCustomTrack(this); Events.trigger(self, 'ended'); } function onTimeUpdate() { //if (isViblastStarted) { // // This is a workaround for viblast not stopping playback at the end // var time = this.currentTime; // var duration = this.duration; // if (duration) { // if (time >= (duration - 1)) { // //onEnded(); // return; // } // } //} if (options.type == 'video') { // Get the player position + the transcoding offset var timeMs = this.currentTime * 1000; timeMs += ((currentPlayOptions.startTimeTicksOffset || 0) / 10000); updateSubtitleText(timeMs); } Events.trigger(self, 'timeupdate'); } function onVolumeChange() { Events.trigger(self, 'volumechange'); } function onOneAudioPlaying(e) { var elem = e.target; elem.removeEventListener('playing', onOneAudioPlaying); document.querySelector('.mediaPlayerAudioContainer').classList.add('hide'); } function onPlaying() { Events.trigger(self, 'playing'); } function onPlay() { Events.trigger(self, 'play'); } function onPause() { Events.trigger(self, 'pause'); } function onClick() { Events.trigger(self, 'click'); } function onDblClick() { Events.trigger(self, 'dblclick'); } function onError(e) { destroyCustomTrack(this); var elem = e.target; var errorCode = elem.error ? elem.error.code : ''; console.log('Media element error code: ' + errorCode); Events.trigger(self, 'error'); } function onLoadedMetadata(e) { var elem = e.target; elem.removeEventListener('loadedmetadata', onLoadedMetadata); if (!hlsPlayer) { elem.play(); } } function requireHlsPlayer(callback) { require(['hlsjs'], function (hls) { window.Hls = hls; callback(); }); } function onOneVideoPlaying(e) { var element = e.target; element.removeEventListener('playing', onOneVideoPlaying); self.setCurrentTrackElement(subtitleTrackIndexToSetOnPlaying); var requiresNativeControls = !self.enableCustomVideoControls(); if (requiresNativeControls) { element.setAttribute('controls', 'controls'); } if (requiresSettingStartTimeOnStart) { var startPositionInSeekParam = currentPlayOptions.startPositionInSeekParam; // Appending #t=xxx to the query string doesn't seem to work with HLS if (startPositionInSeekParam && currentSrc.indexOf('.m3u8') != -1) { var delay = browser.safari ? 2500 : 0; if (delay) { setTimeout(function () { element.currentTime = startPositionInSeekParam; }, delay); } else { element.currentTime = startPositionInSeekParam; } } } } function createAudioElement() { var elem = document.querySelector('.mediaPlayerAudio'); if (!elem) { var html = ''; var requiresControls = !MediaPlayer.canAutoPlayAudio(); if (requiresControls) { html += '
';; } else { html += '
';; } html += '
'; document.body.insertAdjacentHTML('beforeend', html); elem = document.querySelector('.mediaPlayerAudio'); } elem.addEventListener('playing', onOneAudioPlaying); elem.addEventListener('timeupdate', onTimeUpdate); elem.addEventListener('ended', onEnded); elem.addEventListener('volumechange', onVolumeChange); elem.addEventListener('error', onError); elem.addEventListener('pause', onPause); elem.addEventListener('play', onPlay); elem.addEventListener('playing', onPlaying); return elem; } function enableHlsPlayer(src, item, mediaSource) { if (src) { if (src.indexOf('.m3u8') == -1) { return false; } } if (MediaPlayer.canPlayHls()) { if (window.MediaSource == null) { return false; } if (MediaPlayer.canPlayNativeHls()) { // simple playback should use the native support if (mediaSource.RunTimeTicks) { return false; } //return false; } // For now don't do this in edge because we lose some native audio support if (browser.edge && browser.mobile) { return false; } // hls.js is only in beta. needs more testing. if (browser.safari) { return false; } return true; } return false; } function getCrossOriginValue(mediaSource) { return 'anonymous'; } function createVideoElement() { var html = ''; var requiresNativeControls = !self.enableCustomVideoControls(); // Safari often displays the poster under the video and it doesn't look good var poster = !browser.safari && options.poster ? (' poster="' + options.poster + '"') : ''; // Can't autoplay in these browsers so we need to use the full controls if (requiresNativeControls && AppInfo.isNativeApp && browser.android) { html += '