Advertisement
Guest User

OggPlayer.js

a guest
Mar 23rd, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is a global configuration object which can embed multiple video instances
  2. var wgOggPlayer = {
  3.     'detectionDone': false,
  4.     'msie': false,
  5.     'safari' : false,
  6.     'opera' : false,
  7.     'mozilla': false,
  8.     'safariControlsBug': false,
  9.  
  10.     // List of players in order of preference
  11.     // Downpreffed VLC because it crashes my browser all the damn time -- TS
  12.     'players': ['videoElement', 'cortado', 'quicktime-mozilla', 'quicktime-activex', 'vlc-mozilla', 'vlc-activex', 'totem', 'kmplayer', 'kaffeine', 'mplayerplug-in', 'oggPlugin'],
  13.  
  14.     // Client support table
  15.     'clientSupports': { 'thumbnail' : true },
  16.  
  17.     // MIME type to be used to invoke a given plugin with <object>
  18.     // May be changed by detect()
  19.     'mimeTypes' : {
  20.         'quicktime-mozilla': 'video/quicktime',
  21.         'quicktime-activex': 'video/quicktime',
  22.         'vlc-mozilla': 'application/x-vlc-plugin',
  23.         'oggPlugin': 'application/ogg',
  24.         'totem': 'application/ogg',
  25.         'kmplayer': 'application/ogg',
  26.         'kaffeine': 'application/ogg',
  27.         'mplayerplug-in': 'application/ogg'
  28.     },
  29.  
  30.     // by binarymaster / 2017-03-23
  31.     'playlistEnable': true,
  32.     'playlistRepeat': true,
  33.  
  34.     'savedThumbs': {},
  35.     'qtTimers' : {},
  36.     // Text for new messages, to support cached HTML invocation
  37.     'defaultMsg' : {
  38.         'ogg-player-totem': 'Totem',
  39.         'ogg-player-kmplayer': 'KMPlayer',
  40.         'ogg-player-kaffeine': 'Kaffeine',
  41.         'ogg-player-mplayerplug-in': 'mplayerplug-in'
  42.     },
  43.  
  44.     // Configuration from MW
  45.     'msg': {},
  46.     'cortadoUrl' : '',
  47.     'extPathUrl' : '',
  48.     'showPlayerSelect': true,
  49.     'controlsHeightGuess': 20,
  50.  
  51.     /**
  52.      * Main entry point: initialise a video player
  53.      * Player will be created as a child of the given ID
  54.      * There may be multiple players in a document.
  55.      * Parameters are: id, videoUrl, width, height, length, linkUrl, isVideo
  56.      */
  57.     'init': function ( player, params ) {
  58.         // Expand params.videoUrl if protocol-relative
  59.         if ( params.videoUrl.substr( 0, 2 ) == '//' ) {
  60.             // window.location.protocol is something like 'http:'
  61.             params.videoUrl = window.location.protocol + params.videoUrl;
  62.         }
  63.         elt = document.getElementById( params.id );
  64.  
  65.         // Save still image HTML
  66.         if ( !(params.id in this.savedThumbs) ) {
  67.             var thumb = document.createDocumentFragment();
  68.             for ( i = 0; i < elt.childNodes.length; i++ ) {
  69.                 thumb.appendChild( elt.childNodes.item( i ).cloneNode( true ) );
  70.             }
  71.             this.savedThumbs[params.id] = thumb;
  72.         }
  73.  
  74.         this.detect();
  75.  
  76.         if ( !player ) {
  77.             // See if there is a cookie specifying a preferred player
  78.             var cookieVal = this.getCookie( 'ogg_player' );
  79.             if ( cookieVal && cookieVal != 'thumbnail' ) {
  80.                 player = cookieVal;
  81.             }
  82.         }
  83.  
  84.         if ( !this.clientSupports[player] ) {
  85.             player = false;
  86.         }
  87.  
  88.         if ( !player ) {
  89.             for ( var i = 0; i < this.players.length; i++ ) {
  90.                 if ( this.clientSupports[this.players[i]] ) {
  91.                     player = this.players[i];
  92.                     break;
  93.                 }
  94.             }
  95.         }
  96.  
  97.         elt.innerHTML = '';
  98.         switch ( player ) {
  99.             case 'videoElement':
  100.                 this.embedVideoElement( elt, params );
  101.                 break;
  102.             case 'oggPlugin':
  103.             case 'kaffeine':
  104.             case 'totem':
  105.             case 'kmplayer':
  106.             case 'mplayerplug-in':
  107.                 this.embedOggPlugin( elt, params, player );
  108.                 break;
  109.             case 'vlc-mozilla':
  110.                 this.embedVlcPlugin( elt, params );
  111.                 break;
  112.             case 'vlc-activex':
  113.                 this.embedVlcActiveX( elt, params );
  114.                 break;
  115.             case 'cortado':
  116.                 this.embedCortado( elt, params );
  117.                 break;
  118.             case 'quicktime-mozilla':
  119.             case 'quicktime-activex':
  120.                 this.embedQuicktimePlugin( elt, params, player );
  121.                 break;
  122.             case 'thumbnail':
  123.             default:
  124.                 if ( params.id in this.savedThumbs ) {
  125.                     elt.appendChild( this.savedThumbs[params.id].cloneNode( true ) );
  126.                 } else {
  127.                     elt.appendChild( document.createTextNode( 'Missing saved thumbnail for ' + params.id ) );
  128.                 }
  129.                 if ( player != 'thumbnail' ) {
  130.                     var div = document.createElement( 'div' );
  131.                     div.className = 'ogg-player-options';
  132.                     div.style.cssText = 'width: ' + ( params.width - 10 ) + 'px;';
  133.                     div.innerHTML = this.msg['ogg-no-player'];
  134.                     elt.appendChild( div );
  135.                     player = 'none';
  136.                 }
  137.         }
  138.         if ( player != 'thumbnail' ) {
  139.             var optionsBox = this.makeOptionsBox( player, params );
  140.             var optionsLink = this.makeOptionsLink( params.id );
  141.             var div = document.createElement( 'div' );
  142.             div.appendChild( optionsBox );
  143.             div.appendChild( optionsLink );
  144.             elt.appendChild( div );
  145.         }
  146.     },
  147.  
  148.     'debug': function( s ) {
  149.         //alert(s);
  150.     },
  151.  
  152.     // Search for a plugin in navigator.plugins
  153.     'hasPlugin': function( mimeType ) {
  154.         for ( var i = 0; i < navigator.plugins.length; i++ ) {
  155.             var plugin = navigator.plugins[i];
  156.             if ( typeof plugin[mimeType] != "undefined" ) {
  157.                 return true;
  158.             }
  159.         }
  160.         return false;
  161.     },
  162.  
  163.     // Detect client capabilities
  164.     'detect': function() {
  165.         if (this.detectionDone) {
  166.             return;
  167.         }
  168.         this.detectionDone = true;
  169.  
  170.         // First some browser detection
  171.         this.msie = ( navigator.appName == "Microsoft Internet Explorer" );
  172.         this.mozilla = ( navigator.appName == "Netscape" );
  173.         this.opera = ( navigator.appName == 'Opera' );
  174.         this.safari = ( navigator.vendor && navigator.vendor.substr( 0, 5 ) == 'Apple' );
  175.         this.konqueror = ( navigator.appName == 'Konqueror' );
  176.        
  177.         // In Mozilla, navigator.javaEnabled() only tells us about preferences, we need to
  178.         // search navigator.mimeTypes to see if it's installed
  179.         var javaEnabled = navigator.javaEnabled();
  180.         // In Opera, navigator.javaEnabled() is all there is
  181.         var invisibleJava = this.opera;
  182.  
  183.         // Opera will switch off javaEnabled in preferences if java can't be found.
  184.         // And it doesn't register an application/x-java-applet mime type like Mozilla does.
  185.         if ( invisibleJava && javaEnabled ) {
  186.             this.clientSupports['cortado'] = true;
  187.         }
  188.  
  189.         if ( this.konqueror ) {
  190.             // Java is bugged as of 3.5.9
  191.             // Applet freezes shortly after starting
  192.             javaEnabled = false;
  193.         }
  194.  
  195.         if ( this.safari ) {
  196.             // Detect https://bugs.webkit.org/show_bug.cgi?id=25575
  197.             var match = /AppleWebKit\/([0-9]+)/.exec( navigator.userAgent );
  198.             if ( match && parseInt( match[1] ) < 531 ) {
  199.                 this.safariControlsBug = true;
  200.             }
  201.         }
  202.  
  203.         // ActiveX plugins
  204.         // VLC
  205.         if ( this.testActiveX( 'VideoLAN.VLCPlugin.2' ) ) {
  206.             this.clientSupports['vlc-activex'] = true;
  207.         }
  208.         // Java
  209.         if ( javaEnabled && this.testActiveX( 'JavaWebStart.isInstalled' ) ) {
  210.             this.clientSupports['cortado'] = true;
  211.         }
  212.         // QuickTime
  213.         if ( this.testActiveX( 'QuickTimeCheckObject.QuickTimeCheck.1' ) ) {
  214.             this.clientSupports['quicktime-activex'] = true;
  215.         }
  216.  
  217.         // <video> element
  218.         if ( typeof HTMLVideoElement == 'object' // Firefox, Safari
  219.                 || typeof HTMLVideoElement == 'function' ) // Opera
  220.         {
  221.             // Safari does not support Theora by default, but later versions implement canPlayType()
  222.             if ( this.safari ) {
  223.                 try {
  224.                     var video = document.createElement( 'video' );
  225.                     if ( video.canPlayType
  226.                         && video.canPlayType( 'video/ogg;codecs="theora,vorbis"' ) == 'probably' )
  227.                     {
  228.                         this.clientSupports['videoElement'] = true;
  229.                     } else if ( this.supportedMimeType( 'video/ogg' ) ) {
  230.                         // On older versions, XiphQT registers a plugin type and also handles <video>
  231.                         this.clientSupports['videoElement'] = true;
  232.                     } else {
  233.                         // TODO: prompt for XiphQT install
  234.                     }
  235.                 } catch ( e ) {}
  236.             } else {
  237.                 this.clientSupports['videoElement'] = true;
  238.             }
  239.         }
  240.  
  241.         if (!navigator.mimeTypes || navigator.mimeTypes.length == 0) {
  242.             // No Mozilla plugins, all done
  243.             return;
  244.         }
  245.  
  246.         // Mozilla plugins
  247.         var typesByPlayer = {};
  248.         var playersByType = {};
  249.         var numPlayersByType = {};
  250.         var player;
  251.         var i;
  252.         for ( i = 0; i < navigator.mimeTypes.length; i++) {
  253.             var entry = navigator.mimeTypes[i];
  254.             var type = entry.type;
  255.             var semicolonPos = type.indexOf( ';' );
  256.             if ( semicolonPos > -1 ) {
  257.                 type = type.substr( 0, semicolonPos );
  258.             }
  259.  
  260.             var plugin = entry.enabledPlugin;
  261.             // In case it is null or undefined
  262.             var pluginName = plugin && plugin.name ? plugin.name : '';
  263.             var pluginFilename = plugin && plugin.filename ? plugin.filename : '';
  264.             player = '';
  265.  
  266.             if ( javaEnabled && type == 'application/x-java-applet' ) {
  267.                 // We use <applet> so we don't have to worry about unique types
  268.                 this.clientSupports['cortado'] = true;
  269.                 // But it could conflict with another plugin
  270.                 // Set player='' to avoid double registration of cortado
  271.                 player = '';
  272.             } else if ( pluginFilename.indexOf( 'libtotem' ) > -1 ) {
  273.                 // Totem
  274.                 player = 'totem';
  275.             } else if ( pluginFilename.indexOf( 'libkmplayerpart' ) > -1 ) {
  276.                 // KMPlayer is fussy about what type you give it
  277.                 if ( pluginName == 'Windows Media Player Plugin'
  278.                         || pluginName == 'QuickTime Plug-in' )
  279.                 {
  280.                     player = 'kmplayer';
  281.                 }
  282.             } else if ( pluginFilename.indexOf( 'kaffeineplugin' ) > -1 ) {
  283.                 // Kaffeine
  284.                 player = 'kaffeine';
  285.             } else if ( pluginName.indexOf( 'mplayerplug-in' ) > -1 ) {
  286.                 player = 'mplayerplug-in';
  287.             } else if ( pluginFilename.indexOf( 'mplayerplug-in-qt' ) > -1 ) {
  288.                 // MPlayer fake QuickTime
  289.                 player = '';
  290.             } else if ( pluginName.indexOf( 'QuickTime Plug-in' ) > -1 ) {
  291.                 // Note: Totem and KMPlayer also use this pluginName, which is
  292.                 // why we check for them first
  293.                 player = 'quicktime-mozilla';
  294.             } else if ( (pluginName.toLowerCase() == 'vlc multimedia plugin')
  295.                     || (pluginName.toLowerCase() == 'vlc multimedia plug-in') )
  296.             {
  297.                 player = 'vlc-mozilla';
  298.             } else if ( type == 'application/ogg' ) {
  299.                 player = 'oggPlugin';
  300.             }
  301.  
  302.             if ( this.konqueror && player == 'vlc-mozilla' ) {
  303.                 // In Konqueror 3.5.9, VLC is not scriptable, has no controls, and crashes the browser
  304.                 player = '';
  305.             }
  306.  
  307.             // Update some hashtables to track unique type assignment
  308.             // Slightly complicated because players can and do conflict with themselves
  309.             if ( !( player in typesByPlayer ) ) {
  310.                 typesByPlayer[player] = {};
  311.             }
  312.             typesByPlayer[player][type] = true;
  313.             if ( !( type in playersByType ) ) {
  314.                 playersByType[type] = {};
  315.                 numPlayersByType[type] = 0;
  316.             }
  317.             if ( !( player in playersByType[type] ) ) {
  318.                 playersByType[type][player] = true;
  319.                 numPlayersByType[type]++;
  320.             }
  321.         }
  322.  
  323.         // Determine a unique MIME type for each player found
  324.         for ( i = 0; i < this.players.length; i++ ) {
  325.             player = this.players[i];
  326.             if ( !( player in typesByPlayer ) ) {
  327.                 continue;
  328.             }
  329.             // Is the default OK?
  330.             var defaultType = this.mimeTypes[player];
  331.             if ( defaultType in numPlayersByType
  332.                     && numPlayersByType[defaultType] == 1
  333.                     && defaultType in typesByPlayer[player] )
  334.             {
  335.                 // Yes, use it
  336.                 this.debug( player + " -> " + defaultType );
  337.                 this.clientSupports[player] = true;
  338.                 continue;
  339.             }
  340.             // Search for a unique type
  341.             for ( var type in typesByPlayer[player] ) {
  342.                 if ( numPlayersByType[type] == 1 ) {
  343.                     // Found a unique type
  344.                     this.mimeTypes[player] = type;
  345.                     this.clientSupports[player] = true;
  346.                     this.debug( player + " => " + type );
  347.                     break;
  348.                 }
  349.             }
  350.             if ( !(player in this.clientSupports ) ) {
  351.                 if ( typesByPlayer[player].length > 0 ) {
  352.                     this.debug( "No unique MIME type for " + player );
  353.                 } else {
  354.                     this.debug( "No types for player " + player );
  355.                 }
  356.             }
  357.         }
  358.     },
  359.  
  360.     'testActiveX' : function ( name ) {
  361.         if ( this.mozilla ) return false;
  362.         var hasObj = true;
  363.         try {
  364.             // No IE, not a class called "name", it's a variable
  365.             var obj = new ActiveXObject( '' + name );
  366.         } catch ( e ) {
  367.             hasObj = false;
  368.         }
  369.         return hasObj;
  370.     },
  371.  
  372.     'addOption' : function ( select, value, text, selected ) {
  373.             var option = document.createElement( 'option' );
  374.             option.value = value;
  375.             option.appendChild( document.createTextNode( text ) );
  376.             if ( selected ) {
  377.                 option.selected = true;
  378.             }
  379.             select.appendChild( option );
  380.     },
  381.  
  382.     'hx' : function ( s ) {
  383.         if ( typeof s != 'String' ) {
  384.             s = s.toString();
  385.         }
  386.         return s.replace( /&/g, '&amp;' )
  387.             . replace( /</g, '&lt;' )
  388.             . replace( />/g, '&gt;' );
  389.     },
  390.  
  391.     'hq' : function ( s ) {
  392.         return '"' + this.hx( s ) + '"';
  393.     },
  394.  
  395.     'getMsg': function ( key ) {
  396.         if ( key in this.msg ) {
  397.             return this.msg[key];
  398.         } else if ( key in this.defaultMsg ) {
  399.             return this.defaultMsg[key];
  400.         } else {
  401.             return '[' + key + ']';
  402.         }
  403.     },
  404.  
  405.     'makeOptionsBox' : function ( selectedPlayer, params ) {
  406.         var div, p, a, ul, li, button;
  407.  
  408.         div = document.createElement( 'div' );
  409.         div.style.cssText = "width: " + ( params.width - 10 ) + "px; display: none;";
  410.         div.className = 'ogg-player-options';
  411.         div.id = params.id + '_options_box';
  412.         div.align = 'center';
  413.  
  414.         ul = document.createElement( 'ul' );
  415.  
  416.         // Description page link
  417.         if ( params.linkUrl ) {
  418.             li = document.createElement( 'li' );
  419.             a = document.createElement( 'a' );
  420.             a.href = params.linkUrl;
  421.             a.appendChild( document.createTextNode( this.msg['ogg-desc-link'] ) );
  422.             li.appendChild( a );
  423.             ul.appendChild( li );
  424.         }
  425.  
  426.         // Download link
  427.         li = document.createElement( 'li' );
  428.         a = document.createElement( 'a' );
  429.         a.href = params.videoUrl;
  430.         a.appendChild( document.createTextNode( this.msg['ogg-download'] ) );
  431.         li.appendChild( a );
  432.         ul.appendChild( li );
  433.        
  434.         div.appendChild( ul );
  435.  
  436.         // Player list caption
  437.         p = document.createElement( 'p' );
  438.         p.appendChild( document.createTextNode( this.msg['ogg-use-player'] ) );
  439.         div.appendChild( p );
  440.  
  441.         // Make player list
  442.         ul = document.createElement( 'ul' );
  443.         for ( var i = 0; i < this.players.length + 1; i++ ) {
  444.             var player, playerMsg;
  445.             if ( i == this.players.length ) {
  446.                 player = 'thumbnail';
  447.                 if ( params.isVideo ) {
  448.                     playerMsg = 'ogg-player-thumbnail';
  449.                 } else {
  450.                     playerMsg = 'ogg-player-soundthumb';
  451.                 }
  452.             } else {
  453.                 player = this.players[i];
  454.                 // Skip unsupported players
  455.                 if ( ! this.clientSupports[player] ) {
  456.                     continue;
  457.                 }
  458.                 playerMsg = 'ogg-player-' + player;
  459.             }
  460.  
  461.             // Make list item
  462.             li = document.createElement( 'li' );
  463.             if ( player == selectedPlayer ) {
  464.                 var strong = document.createElement( 'strong' );
  465.                 strong.appendChild( document.createTextNode(
  466.                     this.getMsg(playerMsg) + ' ' + this.msg['ogg-player-selected'] ) );
  467.                 li.appendChild( strong );
  468.             } else {
  469.                 a = document.createElement( 'a' );
  470.                 a.href = 'javascript:void("' + player + '")';
  471.                 a.onclick = this.makePlayerFunction( player, params );
  472.                 a.appendChild( document.createTextNode( this.getMsg(playerMsg) ) );
  473.                 li.appendChild( a );
  474.             }
  475.             ul.appendChild( li );
  476.         }
  477.         div.appendChild( ul );
  478.        
  479.         div2 = document.createElement( 'div' );
  480.         div2.style.cssText = 'text-align: center;';
  481.         button = document.createElement( 'button' );
  482.         button.appendChild( document.createTextNode( this.msg['ogg-dismiss'] ) );
  483.         button.onclick = this.makeDismissFunction( params.id );
  484.         div2.appendChild( button );
  485.         div.appendChild( div2 );
  486.  
  487.         return div;
  488.     },
  489.  
  490.     'makeOptionsLink' : function ( id ) {
  491.         var a = document.createElement( 'a' );
  492.         a.href = 'javascript:void("options")';
  493.         a.id = id + '_options_link';
  494.         a.onclick = this.makeDisplayOptionsFunction( id );
  495.         a.appendChild( document.createTextNode( this.msg['ogg-more'] ) );
  496.         return a;
  497.     },
  498.  
  499.     'setCssProperty' : function ( elt, prop, value ) {
  500.         // Could use style.setProperty() here if it worked in IE
  501.         var re = new RegExp( prop + ':[^;](;|$)' );
  502.         if ( elt.style.cssText.search( re ) > -1 ) {
  503.             elt.style.cssText = elt.style.cssText.replace( re, prop + ':' + value + '$1' );
  504.         } else if ( elt.style.cssText == '' ) {
  505.             elt.style.cssText = prop + ':' + value + ';';
  506.         } else if ( elt.style.cssText[elt.style.cssText.length - 1] == ';' ) {
  507.             elt.style.cssText += prop + ':' + value + ';';
  508.         } else {
  509.             elt.style.cssText += ';' + prop + ':' + value + ';';
  510.         }
  511.     },
  512.  
  513.     'makeDismissFunction' : function ( id ) {
  514.         var this_ = this;
  515.         return function () {
  516.             var optionsLink = document.getElementById( id + '_options_link' );
  517.             var optionsBox = document.getElementById( id + '_options_box' );
  518.             this_.setCssProperty( optionsLink, 'display', 'inline' );
  519.             this_.setCssProperty( optionsBox, 'display', 'none' );
  520.         }
  521.     },
  522.  
  523.     'makeDisplayOptionsFunction' : function ( id ) {
  524.         var this_ = this;
  525.         return function () {
  526.             var optionsLink = document.getElementById( id + '_options_link' );
  527.             var optionsBox = document.getElementById( id + '_options_box' );
  528.             this_.setCssProperty( optionsLink, 'display', 'none' );
  529.             this_.setCssProperty( optionsBox, 'display', 'block' );
  530.         }
  531.     },
  532.  
  533.     'makePlayerFunction' : function ( player, params ) {
  534.         var this_ = this;
  535.         return function () {
  536.             if ( player != 'thumbnail' ) {
  537.                 var week = 7*86400*1000;
  538.                 this_.setCookie( 'ogg_player', player, week, false, false, false, false );
  539.             }
  540.             this_.init( player, params );
  541.         };
  542.     },
  543.  
  544.     'newButton': function ( caption, image, callback ) {
  545.         var elt = document.createElement('input');
  546.         elt.type = 'image';
  547.         elt.src = this.extPathUrl + '/' + image;
  548.         elt.alt = elt.value = elt.title = this.msg[caption];
  549.         elt.onclick = callback;
  550.         return elt;
  551.     },
  552.  
  553.     'newPlayButton': function ( videoElt ) {
  554.         return this.newButton( 'ogg-play', 'play.png', function () { videoElt.play(); } );
  555.     },
  556.  
  557.     'newPauseButton': function ( videoElt ) {
  558.         return this.newButton( 'ogg-pause', 'pause.png', function () { videoElt.pause(); } );
  559.     },
  560.  
  561.     'newStopButton': function ( videoElt ) {
  562.         return this.newButton( 'ogg-stop', 'stop.png', function () { videoElt.stop(); } );
  563.     },
  564.  
  565.     // by binarymaster / 2017-03-23
  566.     'playTrack' : function ( index ) {
  567.         var player = document.querySelectorAll('div[id=ogg_player_' + index + ']');
  568.         if ( !player.length )
  569.         {
  570.             if ( !this.playlistRepeat ) return false;
  571.             // Roll back to the first track
  572.             player = document.querySelectorAll('div[id=ogg_player_1]');
  573.         }
  574.         // Check whether audio is already loaded
  575.         var elt = player[0].getElementsByTagName('audio');
  576.         if ( elt.length > 0 )
  577.         {
  578.             // Play audio
  579.             elt[0].play();
  580.         }
  581.         else
  582.         {
  583.             // Click button to load audio
  584.             elt = player[0].getElementsByTagName('button');
  585.             elt[0].click();
  586.         }
  587.         return true;
  588.     },
  589.  
  590.     'embedVideoElement': function ( elt, params ) {
  591.         var id = elt.id + "_obj";
  592.         var tagName = params.isVideo ? 'video' : 'audio';
  593.         var html =
  594.             '<div><' + tagName +
  595.                 ' id=' + this.hq( id ) +
  596.                 ' width=' + this.hq( params.width ) +
  597.                 ' height=' + this.hq( (params.height>0)?params.height:this.controlsHeightGuess ) +
  598.                 ' src=' + this.hq( params.videoUrl ) +
  599.                 ' autoplay';
  600.         if ( !this.safariControlsBug ) {
  601.             html += ' controls';
  602.         }
  603.         html += ' ></' + tagName + '></div>';
  604.         elt.innerHTML = html;
  605.         // by binarymaster / 2017-03-23
  606.         if ( this.playlistEnable && !params.isVideo )
  607.         {
  608.             // Detect next track number by parsing current id
  609.             var nextTrack = parseInt(params.id.split('_')[2]) + 1;
  610.             elt.getElementsByTagName('audio')[0].addEventListener('ended', function(el) {
  611.                 // Play next track on playback end
  612.                 wgOggPlayer.playTrack(nextTrack);
  613.             });
  614.         }
  615.     },
  616.  
  617.     'embedOggPlugin': function ( elt, params, player ) {
  618.         var id = elt.id + "_obj";
  619.         elt.innerHTML +=
  620.             "<div><object id=" + this.hq( id ) +
  621.             " type=" + this.hq( this.mimeTypes[player] ) +
  622.             " width=" + this.hq( params.width ) +
  623.             " height=" + this.hq( params.height + this.controlsHeightGuess ) +
  624.             " data=" + this.hq( params.videoUrl ) + "></object></div>";
  625.     },
  626.  
  627.     'embedVlcPlugin' : function ( elt, params ) {
  628.         var id = elt.id + "_obj";
  629.         elt.innerHTML +=    
  630.             "<div><object id=" + this.hq( id ) +
  631.             " type=" + this.hq( this.mimeTypes['vlc-mozilla'] ) +
  632.             " width=" + this.hq( params.width ) +
  633.             " height=" + this.hq( params.height ) +
  634.             " data=" + this.hq( params.videoUrl ) + "></object></div>";
  635.        
  636.         var videoElt = document.getElementById( id );
  637.         var div = document.createElement( 'div' );
  638.         // TODO: seek bar
  639.         div.appendChild( this.newPlayButton( videoElt ) );
  640.         div.appendChild( this.newPauseButton( videoElt ) );
  641.         div.appendChild( this.newStopButton( videoElt ) );
  642.         elt.appendChild( div );
  643.     },
  644.  
  645.     'embedVlcActiveX' : function ( elt, params ) {
  646.         var id = elt.id + "_obj";
  647.  
  648.         elt.innerHTML =
  649.             '<div><object id=' + this.hq( id ) +
  650.             ' classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"' +
  651.             ' codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,6,0"' +
  652.             ' width=' + this.hq( params.width ) +
  653.             ' height=' + this.hq( params.height ) +
  654.             ' style="width: ' + this.hx( params.width ) + 'px; height: ' + this.hx( params.height ) + 'px;"' +
  655.             ">" +
  656.             '<param name="mrl" value=' + this.hq( params.videoUrl ) + '/>' +
  657.             '</object></div>';
  658.  
  659.         var videoElt = document.getElementById( id );
  660.  
  661.         // IE says "sorry, I wasn't listening, what were the dimensions again?"
  662.         if ( params.width && params.height ) {
  663.             videoElt.width = params.width;
  664.             videoElt.height = params.height;
  665.             videoElt.style.width = params.width + 'px';
  666.             videoElt.style.height = params.height + 'px';
  667.         }
  668.         var div = document.createElement( 'div' );
  669.         // TODO: seek bar
  670.         div.appendChild( this.newButton( 'ogg-play', 'play.png', function() { videoElt.playlist.play(); } ) );
  671.         // FIXME: playlist.pause() doesn't work
  672.         div.appendChild( this.newButton( 'ogg-stop', 'stop.png', function() { videoElt.playlist.stop(); } ) );
  673.         elt.appendChild( div );
  674.     },
  675.  
  676.     'embedCortado' : function ( elt, params ) {
  677.         var statusHeight = 18;
  678.         var playerHeight = params.height + statusHeight;
  679.  
  680.         // Create the applet all at once
  681.         // In Opera, document.createElement('applet') immediately creates
  682.         // a non-working applet with unchangeable parameters, similar to the
  683.         // problem with IE and ActiveX.
  684.         var html =
  685.             '<applet code="com.fluendo.player.Cortado.class" ' +
  686.             '      width=' + this.hq( params.width ) +
  687.             '      height=' + this.hq( playerHeight ) +
  688.             '      archive=' + this.hq( this.cortadoUrl ) + '>' +
  689.             '  <param name="url"  value=' + this.hq( params.videoUrl ) + '/>' +
  690.             '  <param name="duration"  value=' + this.hq( params.length ) + '/>' +
  691.             '  <param name="seekable"  value="true"/>' +
  692.             '  <param name="autoPlay" value="true"/>' +
  693.             '  <param name="showStatus"  value="show"/>' +
  694.             '  <param name="showSpeaker" value="false"/>' +
  695.             '  <param name="statusHeight"  value="' + statusHeight + '"/>' +
  696.             '</applet>';
  697.  
  698.         // Wrap it in an iframe to avoid hanging the event thread in FF 2/3 and similar
  699.         // Doesn't work in MSIE or Safari/Mac or Opera 9.5
  700.         if ( this.mozilla ) {
  701.             var iframe = document.createElement( 'iframe' );
  702.             iframe.setAttribute( 'width', params.width );
  703.             iframe.setAttribute( 'height', playerHeight );
  704.             iframe.setAttribute( 'scrolling', 'no' );
  705.             iframe.setAttribute( 'frameborder', 0 );
  706.             iframe.setAttribute( 'marginWidth', 0 );
  707.             iframe.setAttribute( 'marginHeight', 0 );
  708.             elt.appendChild( iframe );
  709.             var newDoc = iframe.contentDocument;
  710.             newDoc.open();
  711.             newDoc.write( '<html><body>' + html + '</body></html>' );
  712.             newDoc.close(); // spurious error in some versions of FF, no workaround known
  713.         } else {
  714.             elt.innerHTML ='<div>' + html + '</div>';
  715.         }
  716.     },
  717.  
  718.     'embedQuicktimePlugin': function ( elt, params, player ) {
  719.         var id = elt.id + "_obj";
  720.         var controllerHeight = 16; // by observation
  721.         var extraAttribs = '';
  722.         if ( player == 'quicktime-activex' ) {
  723.             extraAttribs = 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
  724.         }
  725.  
  726.         elt.innerHTML +=
  727.             "<div><object id=" + this.hq( id ) +
  728.             " type='" + this.mimeTypes[player] + "'" +
  729.             " width=" + this.hq( params.width ) +
  730.             " height=" + this.hq( params.height + controllerHeight ) +
  731.            
  732.             // See http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=25605
  733.             " data=" + this.hq( this.extPathUrl + '/null_file.mov' ) +
  734.             ' ' + extraAttribs +
  735.             ">" +
  736.             // Scale, don't clip
  737.             "<param name='SCALE' value='Aspect'/>" +
  738.             "<param name='AUTOPLAY' value='True'/>" +
  739.             "<param name='src' value=" + this.hq( this.extPathUrl + '/null_file.mov' ) +  "/>" +
  740.             "<param name='QTSRC' value=" + this.hq( params.videoUrl ) + "/>" +
  741.             "</object></div>";
  742.  
  743.         // Poll for completion
  744.         var this_ = this;
  745.         this.qtTimers[params.id] = window.setInterval( this.makeQuickTimePollFunction( params ), 500 );
  746.     },
  747.  
  748.     'makeQuickTimePollFunction' : function ( params ) {
  749.         var this_ = this;
  750.         return function () {
  751.             var elt = document.getElementById( params.id );
  752.             var id = params.id + '_obj';
  753.             var videoElt = document.getElementById( id );
  754.             if ( elt && videoElt ) {
  755.                 // Detect XiphQT (may throw)
  756.                 var xiphQtVersion = false, done = false;
  757.                 try {
  758.                     xiphQtVersion = videoElt.GetComponentVersion('imdc','XiTh', 'Xiph');
  759.                     done = true;
  760.                 } catch ( e ) {}
  761.                 if ( done ) {
  762.                     window.clearInterval( this_.qtTimers[params.id] );
  763.                     if ( !xiphQtVersion || xiphQtVersion == '0.0' ) {
  764.                         var div = document.createElement( 'div' );
  765.                         div.className = 'ogg-player-options';
  766.                         div.style.cssText = 'width:' + ( params.width - 10 ) + 'px;';
  767.                         div.innerHTML = this_.getMsg( 'ogg-no-xiphqt' );
  768.                         var optionsDiv = document.getElementById( params.id + '_options_box' );
  769.                         if ( optionsDiv ) {
  770.                             elt.insertBefore( div, optionsDiv.parentNode );
  771.                         } else {
  772.                             elt.appendChild( div );
  773.                         }
  774.                     }
  775.                     // Disable autoplay on back button
  776.                     this_.setParam( videoElt, 'AUTOPLAY', 'False' );
  777.                 }
  778.             }
  779.         };
  780.     },
  781.  
  782.     'addParam': function ( elt, name, value ) {
  783.         var param = document.createElement( 'param' );
  784.         param.setAttribute( 'name', name );
  785.         param.setAttribute( 'value', value );
  786.         elt.appendChild( param );
  787.     },
  788.  
  789.     'setParam' : function ( elt, name, value ) {
  790.         var params = elt.getElementsByTagName( 'param' );
  791.         for ( var i = 0; i < params.length; i++ ) {
  792.             if ( params[i].name.toLowerCase() == name.toLowerCase() ) {
  793.                 params[i].value = value;
  794.                 return;
  795.             }
  796.         }
  797.         this.addParam( elt, name, value );
  798.     },
  799.  
  800.     'setCookie' : function ( name, value, expiry, path, domain, secure ) {
  801.         var expiryDate = false;
  802.         if ( expiry ) {
  803.             expiryDate = new Date();
  804.             expiryDate.setTime( expiryDate.getTime() + expiry );
  805.         }
  806.         document.cookie = name + "=" + escape(value) +
  807.             (expiryDate ? ("; expires=" + expiryDate.toGMTString()) : "") +
  808.             (path ? ("; path=" + path) : "") +
  809.             (domain ? ("; domain=" + domain) : "") +
  810.             (secure ? "; secure" : "");
  811.     },
  812.  
  813.     'getCookie' : function ( cookieName ) {
  814.         var m = document.cookie.match( cookieName + '=(.*?)(;|$)' );
  815.         return m ? unescape( m[1] ) : false;
  816.     }
  817. };
  818. // vim: ts=4 sw=4 noet cindent :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement