(function () { var supportsTextTracks; var hlsPlayer; var requiresSettingStartTimeOnStart; var subtitleTrackIndexToSetOnPlaying; function htmlMediaRenderer(options) { var mediaElement; var self = this; function hideStatusBar() { if (options.type == 'video' && window.StatusBar) { //StatusBar.backgroundColorByName("black"); //StatusBar.overlaysWebView(true); StatusBar.hide(); } } function showStatusBar() { if (options.type == 'video' && window.StatusBar) { StatusBar.show(); //StatusBar.overlaysWebView(false); } } function onEnded() { showStatusBar(); 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; // } // } //} Events.trigger(self, 'timeupdate'); } function onVolumeChange() { Events.trigger(self, 'volumechange'); } function onOneAudioPlaying(e) { var elem = e.target; elem.removeEventListener('playing', onOneAudioPlaying); $('.mediaPlayerAudioContainer').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) { var elem = e.target; var errorCode = elem.error ? elem.error.code : ''; console.log('Media element error code: ' + errorCode); showStatusBar(); 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 getStartTime(url) { var src = url; var parts = src.split('#'); if (parts.length > 1) { parts = parts[parts.length - 1].split('='); if (parts.length == 2) { return parseFloat(parts[1]); } } return 0; } function onOneVideoPlaying(e) { hideStatusBar(); var element = e.target; element.removeEventListener('playing', onOneVideoPlaying); self.setCurrentTrackElement(subtitleTrackIndexToSetOnPlaying); var requiresNativeControls = !self.enableCustomVideoControls(); if (requiresNativeControls) { $(element).attr('controls', 'controls'); } if (requiresSettingStartTimeOnStart) { var src = (self.currentSrc() || '').toLowerCase(); var startPositionInSeekParam = getStartTime(src); // Appending #t=xxx to the query string doesn't seem to work with HLS if (startPositionInSeekParam && src.indexOf('.m3u8') != -1) { var delay = browserInfo.safari ? 2500 : 0; if (delay) { setTimeout(function () { element.currentTime = startPositionInSeekParam; }, delay); } else { element.currentTime = startPositionInSeekParam; } } } } function createAudioElement() { var elem = $('.mediaPlayerAudio'); if (!elem.length) { var html = ''; var requiresControls = !MediaPlayer.canAutoPlayAudio(); if (requiresControls) { html += '
';; } else { html += ''; $(document.body).append(html); elem = $('.mediaPlayerAudio'); } elem = elem[0]; 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) { if (src) { if (src.indexOf('.m3u8') == -1) { return false; } } return MediaPlayer.canPlayHls() && !MediaPlayer.canPlayNativeHls(); } function createVideoElement() { var html = ''; var requiresNativeControls = !self.enableCustomVideoControls(); // Safari often displays the poster under the video and it doesn't look good var poster = !browserInfo.safari && options.poster ? (' poster="' + options.poster + '"') : ''; // Can't autoplay in these browsers so we need to use the full controls if (requiresNativeControls && AppInfo.isNativeApp && browserInfo.android) { html += '