2012-01-25 23:19:57 +00:00
/ *
< OWNER > = revolunet
< ORGANIZATION > = revolunet - Julien Bouquillon
< YEAR > = 2010
Copyright ( c ) 2010 , revolunet
All rights reserved .
Redistribution and use in source and binary forms , with or without modification , are permitted provided that the following conditions are met :
Redistributions of source code must retain the above copyright notice , this list of conditions and the following disclaimer .
Redistributions in binary form must reproduce the above copyright notice , this list of conditions and the following disclaimer in the documentation and / or other materials provided with the distribution .
Neither the name of the < ORGANIZATION > nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
var VLCobject = {
VLC _PLUGIN : "VLC Multimedia Plug-in"
, VLC _AX : "VideoLAN.VLCPlugin.2"
, VLC _MIME _TYPE : "application/x-vlc-plugin"
2012-07-16 20:29:59 +00:00
, TOOLBAR _HEIGHT : 15
2012-01-25 23:19:57 +00:00
, INSTANCES : { } // holds multiples instances
, UNICODES : {
PLAY : '\u25ba'
, PAUSE : '\u2590 \u258c'
, STOP : '\u2588'
}
, ua : function ( ) {
// browser detection stuff
var w3cdom = typeof document . getElementById != 'undefined' && typeof document . getElementsByTagName != 'undefined' && typeof document . createElement != 'undefined' ,
u = navigator . userAgent . toLowerCase ( ) ,
p = navigator . platform . toLowerCase ( ) ,
windows = p ? /win/ . test ( p ) : /win/ . test ( u ) ,
mac = p ? /mac/ . test ( p ) : /mac/ . test ( u ) ,
webkit = /webkit/ . test ( u ) ? parseFloat ( u . replace ( /^.*webkit\/(\d+(\.\d+)?).*$/ , "$1" ) ) : false , // returns either the webkit version or false if not webkit
ie = ! + "\v1" , // feature detection based on Andrea Giammarchi's solution: http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
playerVersion = [ 0 , 0 , 0 ] ,
d = null ;
if ( typeof navigator . plugins != 'undefined' && typeof navigator . plugins [ this . VLC _PLUGIN ] == 'object' ) {
d = navigator . plugins [ this . VLC _PLUGIN ] . description ;
if ( d && ! ( typeof navigator . mimeTypes != 'undefined' && navigator . mimeTypes [ this . VLC _MIME _TYPE ] && ! navigator . mimeTypes [ this . VLC _MIME _TYPE ] . enabledPlugin ) ) { // navigator.mimeTypes[VLC_MIME_TYPE].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
plugin = true ;
ie = false ; // cascaded feature detection for Internet Explorer
d = d . replace ( /^.*\s+(\S+\s+\S+$)/ , "$1" ) ;
playerVersion [ 0 ] = parseInt ( d . replace ( /^(.*)\..*$/ , "$1" ) , 10 ) ;
playerVersion [ 1 ] = parseInt ( d . replace ( /^.*\.(.*)\s.*$/ , "$1" ) , 10 ) ;
playerVersion [ 2 ] = /[a-zA-Z]/ . test ( d ) ? parseInt ( d . replace ( /^.*[a-zA-Z]+(.*)$/ , "$1" ) , 10 ) : 0 ;
}
}
else if ( typeof window . ActiveXObject != 'undefined' ) {
try {
var a = new ActiveXObject ( this . VLC _AX ) ;
if ( a ) { // a will return null when ActiveX is disabled
d = a . GetVariable ( "$version" ) ;
if ( d ) {
ie = true ; // cascaded feature detection for Internet Explorer
d = d . split ( " " ) [ 1 ] . split ( "," ) ;
playerVersion = [ parseInt ( d [ 0 ] , 10 ) , parseInt ( d [ 1 ] , 10 ) , parseInt ( d [ 2 ] , 10 ) ] ;
}
}
}
catch ( e ) { }
}
return { w3 : w3cdom , pv : playerVersion , wk : webkit , ie : ie , win : windows , mac : mac } ;
} ( )
, createVLC : function ( attObj , parObj , id ) {
var r , el = document . getElementById ( id ) ;
if ( el ) {
if ( typeof attObj . id == 'undefined' ) { // if no 'id' is defined for the object element, it will inherit the 'id' from the alternative content
attObj . id = id ;
}
if ( this . ua . ie && this . ua . win ) { // Internet Explorer + the HTML object element + W3C DOM methods do not combine: fall back to outerHTML
var att = "" ;
for ( var i in attObj ) {
if ( attObj [ i ] != Object . prototype [ i ] ) { // filter out prototype additions from other potential libraries
if ( i . toLowerCase ( ) == "data" ) {
parObj . movie = attObj [ i ] ;
}
else if ( i . toLowerCase ( ) == "styleclass" ) { // 'class' is an ECMA4 reserved keyword
att += ' class="' + attObj [ i ] + '"' ;
}
else if ( i . toLowerCase ( ) != "classid" ) {
att += ' ' + i + '="' + attObj [ i ] + '"' ;
}
}
}
var par = "" ;
for ( var j in parObj ) {
if ( parObj [ j ] != Object . prototype [ j ] ) { // filter out prototype additions from other potential libraries
par += '<param name="' + j + '" value="' + parObj [ j ] + '" />' ;
}
}
el . outerHTML = '<object classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"' + att + '>' + par + '</object>' ;
r = document . getElementById ( attObj . id ) ;
}
else { // well-behaving browsers
var o = document . createElement ( 'object' ) ;
o . setAttribute ( "type" , this . VLC _MIME _TYPE ) ;
for ( var m in attObj ) {
if ( attObj [ m ] != Object . prototype [ m ] ) { // filter out prototype additions from other potential libraries
if ( m . toLowerCase ( ) == "styleclass" ) { // 'class' is an ECMA4 reserved keyword
o . setAttribute ( "class" , attObj [ m ] ) ;
}
else if ( m . toLowerCase ( ) != "classid" ) { // filter out IE specific attribute
o . setAttribute ( m , attObj [ m ] ) ;
}
}
}
for ( var n in parObj ) {
if ( parObj [ n ] != Object . prototype [ n ] && n . toLowerCase ( ) != "movie" ) { // filter out prototype additions from other potential libraries and IE specific param element
this . createObjParam ( o , n , parObj [ n ] ) ;
}
}
el . parentNode . replaceChild ( o , el ) ;
r = o ;
}
}
return r ;
}
, createObjParam : function ( el , pName , pValue ) {
var p = document . createElement ( "param" ) ;
p . setAttribute ( "name" , pName ) ;
p . setAttribute ( "value" , pValue ) ;
el . appendChild ( p ) ;
}
/ * C r o s s - b r o w s e r S W F r e m o v a l
- Especially needed to safely and completely remove a SWF in Internet Explorer
* /
, removeVLC : function ( id ) {
var obj = document . getElementById ( id ) ;
if ( obj && obj . nodeName == "OBJECT" ) {
if ( this . ua . ie && this . ua . win ) {
obj . style . display = "none" ;
( function ( ) {
if ( obj . readyState == 4 ) {
this . removeObjectInIE ( id ) ;
}
else {
setTimeout ( arguments . callee , 10 ) ;
}
} ) ( ) ;
}
else {
obj . parentNode . removeChild ( obj ) ;
}
}
}
, removeObjectInIE : function ( id ) {
var obj = document . getElementById ( id ) ;
if ( obj ) {
for ( var i in obj ) {
if ( typeof obj [ i ] == "function" ) {
obj [ i ] = null ;
}
}
obj . parentNode . removeChild ( obj ) ;
}
}
, embedVLC : function ( replaceElemIdStr , widthStr , heightStr , vlcVersionStr , flashvarsObj , parObj , attObj , callbackFn ) {
var callbackObj = { success : false , id : replaceElemIdStr } ;
if ( this . ua . w3 && ! ( this . ua . wk && this . ua . wk < 312 ) && replaceElemIdStr && widthStr && heightStr ) {
//setVisibility(replaceElemIdStr, false);
// addDomLoadEvent(function() {
widthStr += "" ; // auto-convert to string
heightStr += "" ;
var att = { } ;
if ( attObj && typeof attObj === 'object' ) {
for ( var i in attObj ) { // copy object to avoid the use of references, because web authors often reuse attObj for multiple SWFs
att [ i ] = attObj [ i ] ;
}
}
// att.data = swfUrlStr;
att . width = widthStr ;
att . height = heightStr ;
var par = { } ;
if ( parObj && typeof parObj === 'object' ) {
for ( var j in parObj ) { // copy object to avoid the use of references, because web authors often reuse parObj for multiple SWFs
par [ j ] = parObj [ j ] ;
}
}
if ( flashvarsObj && typeof flashvarsObj === 'object' ) {
for ( var k in flashvarsObj ) { // copy object to avoid the use of references, because web authors often reuse flashvarsObj for multiple SWFs
if ( typeof par . flashvars != 'undefined' ) {
par . flashvars += "&" + k + "=" + flashvarsObj [ k ] ;
}
else {
par . flashvars = k + "=" + flashvarsObj [ k ] ;
}
}
}
if ( ! vlcVersionStr || hasPlayerVersion ( vlcVersionStr ) ) { // create SWF
var obj = this . createVLC ( att , par , replaceElemIdStr ) ;
if ( document . all ) {
obj . style . width = widthStr ;
obj . style . height = heightStr ;
}
if ( att . id == replaceElemIdStr ) {
//setVisibility(replaceElemIdStr, true);
}
callbackObj . success = true ;
callbackObj . ref = obj ;
}
else { // show alternative content
//setVisibility(replaceElemIdStr, true);
}
if ( callbackFn ) { callbackFn ( callbackObj ) ; }
// });
}
else if ( callbackFn ) { callbackFn ( callbackObj ) ; }
}
, embedPlayer : function ( replaceElemIdStr , widthStr , heightStr , add _toolbar ) {
var tbHeight = add _toolbar ? this . TOOLBAR _HEIGHT : 0 ;
var plugin _height = ( parseInt ( heightStr ) - tbHeight ) ;
$ ( '#' + replaceElemIdStr ) . html ( '' ) ;
$ ( '#' + replaceElemIdStr ) . height ( parseInt ( heightStr ) ) ;
var tbar = "<div id='" + replaceElemIdStr + "-main' class='x-vlc-main' style='width:" + widthStr + "px;height:" + heightStr + "px' >" ;
tbar += "<div id='" + replaceElemIdStr + "_plugin' class='x-vlc-plugin' ></div>" ;
tbar += "<div style='overflow:hide;width:" + widthStr + "px;height:" + tbHeight + "px' id='" + replaceElemIdStr + "_toolbar', class='x-vlc-toolbar' ></div>" ;
tbar += "</div>" ;
$ ( '#' + replaceElemIdStr ) . append ( tbar )
this . embedVLC ( replaceElemIdStr + '_plugin' , widthStr , plugin _height . toString ( ) ) ;
if ( typeof ( this . INSTANCES [ replaceElemIdStr ] ) == 'undefined' ) {
this . INSTANCES [ replaceElemIdStr ] = playerInstance ( replaceElemIdStr ) ;
}
if ( add _toolbar ) {
this . addToolbar ( replaceElemIdStr ) ;
}
else {
$ ( '#' + replaceElemIdStr + '_toolbar' ) . hide ( ) ; //default hide toolba
}
//this.INSTANCES[replaceElemIdStr].addEvents();
return this . INSTANCES [ replaceElemIdStr ] ;
}
, addToolbar : function ( playerId ) {
if ( ! playerId ) playerId = this . INSTANCES [ 0 ] ;
var instance = this . INSTANCES [ playerId ] ;
var tgt = $ ( '#' + playerId + '_toolbar' ) ;
tgt . html ( '' ) ;
this . createButton ( playerId , ' ' , 'x-vlc-btn-play' , function ( event ) {
2012-07-16 20:29:59 +00:00
event . data . instance . togglePlay ( ) ;
} , 25 ) ;
2012-01-25 23:19:57 +00:00
this . createButton ( playerId , ' ' , 'x-vlc-btn-stop' , function ( event ) {
//alert('stop '+ event.data.instance.playerId);
event . data . instance . stop ( ) ;
} ) ;
2012-07-16 20:29:59 +00:00
this . createButton ( playerId , ' ' , 'x-vlc-btn-rew' , function ( event ) {
event . data . instance . slower ( ) ;
} ) ;
this . createButton ( playerId , ' ' , 'x-vlc-btn-ff' , function ( event ) {
event . data . instance . faster ( ) ;
} ) ;
this . createSpeed ( playerId ) ;
//instance.createSlider();
2012-01-25 23:19:57 +00:00
this . getInstance ( playerId ) . statusChanged ( ) ;
2012-07-16 20:29:59 +00:00
//this.createTimer(playerId);
2012-01-25 23:19:57 +00:00
this . createButton ( playerId , ' ' , 'x-vlc-btn-fullscreen' , function ( event ) {
//alert('stop '+ event.data.instance.playerId);
event . data . instance . toggleFullscreen ( ) ;
} ) ;
2012-07-16 20:29:59 +00:00
this . createButton ( playerId , ' ' , 'x-vlc-btn-sub' , function ( event ) {
2012-01-25 23:19:57 +00:00
//alert('stop '+ event.data.instance.playerId);
2012-07-16 20:29:59 +00:00
event . data . instance . toggleSubtitles ( ) ;
2012-01-25 23:19:57 +00:00
} ) ;
2012-07-16 20:29:59 +00:00
this . createStatus ( playerId ) ;
// this.createButton(playerId, ' ', 'x-vlc-btn-plus', function(event) {
// //alert('stop '+ event.data.instance.playerId);
// // event.data.instance.stop();
// $('#' + instance.playerId + '_about').slideToggle(0);
// });
2012-01-25 23:19:57 +00:00
aboutTxt = "" ;
if ( instance . version ( ) ) {
aboutTxt = 'Installed version: ' + instance . version ( ) ;
}
else {
var url = "http://www.videolan.org/vlc/" ;
aboutTxt = "VLC not detected. <a href='" + url + "' target='blank'>click here to install</a>" ;
}
tgt . append ( '<div id="' + playerId + '_about" class="x-vlc-about" style="display:none" class="x-vlc-about">' + aboutTxt + '</div>' ) ;
tgt . show ( ) ;
}
, remove : function ( playerId ) {
if ( ! playerId ) playerId = this . INSTANCES [ 0 ] ;
delete this . INSTANCES [ playerId ] ;
}
2012-07-16 20:29:59 +00:00
, createButton : function ( playerId , html , cls , handler , width ) {
if ( ! width ) width = 16 ;
2012-01-25 23:19:57 +00:00
var tgt = $ ( '#' + playerId + '_toolbar' ) ;
var id = playerId + '_toolbar_btn' + tgt [ 0 ] . childNodes . length ;
2012-07-16 20:29:59 +00:00
var btn = "<div id='" + id + "' style='float:left;width:" + width + "px;text-align:center;cursor:pointer' class='x-vlc-btn " + cls + "' >" + html + "</div>" ;
2012-01-25 23:19:57 +00:00
tgt . append ( btn ) ;
var instance = this . getInstance ( playerId ) ;
if ( handler ) {
$ ( '#' + id ) . bind ( 'click' , { instance : instance } , handler ) ;
}
}
2012-07-16 20:29:59 +00:00
, createSpeed : function ( playerId ) {
var tgt = $ ( '#' + playerId + '_toolbar' ) ;
var speed = "<div id='" + playerId + "_speed' style='float:left;text-align:center;width:100px' class='x-vlc-timer'> x1 </div>"
tgt . append ( speed ) ;
}
, createStatus : function ( playerId ) {
var tgt = $ ( '#' + playerId + '_toolbar' ) ;
var status = "<div id='" + playerId + "_status' style='float:left;text-align:center;width:200px' class='x-vlc-status'> </div>"
tgt . append ( status ) ;
}
2012-01-25 23:19:57 +00:00
, createTimer : function ( playerId ) {
var tgt = $ ( '#' + playerId + '_toolbar' ) ;
var timer = "<div id='" + playerId + "_timer' style='float:left;text-align:center;width:100px' class='x-vlc-timer'> 00:00/00:00 </div>"
tgt . append ( timer ) ;
}
, getInstance : function ( playerId ) {
return this . INSTANCES [ playerId ] ;
}
}
function playerInstance ( playerId ) {
var instance = {
playerId : playerId
, toolbar : + '_toolbar'
, slider : playerId + '_toolbar_slider'
, sliderCreated : false
, btn _play : playerId + '_toolbar_btn0'
, plugin : playerId + '_plugin'
, timer : playerId + '_timer'
2012-07-16 20:29:59 +00:00
, speed : playerId + '_speed'
, stat : playerId + '_status'
2012-01-25 23:19:57 +00:00
, status : null
, _ _getPlugin : function ( ) {
return $ ( '#' + this . plugin ) [ 0 ] ;
}
// JS API
, version : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
if ( ! plugin ) return false ;
var version = plugin . versionInfo ;
if ( typeof ( version ) == "function" ) version = plugin . versionInfo ( ) ;
return version ;
}
, queue : function ( uri ) {
var plugin = this . _ _getPlugin ( ) ;
if ( ! plugin ) {
setTimeout ( "VLCobject.getInstance('" + this . playerId + "').play('" + uri + "');" , 500 ) ;
return ;
}
var options = this . options . get ( ) ;
var id = plugin . playlist . add ( uri , uri , options ) ;
// plugin.playlist.playItem(id);
}
2012-07-16 20:29:59 +00:00
, play : function ( uri , duration ) {
2012-01-25 23:19:57 +00:00
var plugin = this . _ _getPlugin ( ) ;
if ( ! plugin ) {
setTimeout ( "VLCobject.getInstance('" + this . playerId + "').play('" + uri + "');" , 500 ) ;
return ;
}
var options = this . options . get ( ) ;
2012-07-16 20:29:59 +00:00
2012-01-25 23:19:57 +00:00
this . statusCheckStart ( ) ;
if ( uri ) {
var id = plugin . playlist . add ( uri , uri , options ) ;
plugin . playlist . playItem ( id ) ;
}
else {
plugin . playlist . play ( ) ;
}
}
, seek : function ( percentage ) {
var plugin = this . _ _getPlugin ( ) ;
if ( plugin . input . length > 0 ) {
plugin . input . time = plugin . input . length * percentage / 100 ;
}
}
, toggleFullscreen : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
plugin . video . toggleFullscreen ( ) ;
//plugin.video.fullscreen();
}
2012-07-16 20:29:59 +00:00
, toggleSubtitles : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
var tgt = $ ( '.x-vlc-btn-sub' ) ;
if ( plugin . subtitle . track )
{
tgt . removeClass ( 'x-vlc-btn-sub-clicked' ) ;
plugin . subtitle . track = 0 ;
this . setStatus ( 'Subtitles disabled.' ) ;
}
else
{
tgt . addClass ( 'x-vlc-btn-sub-clicked' ) ;
plugin . subtitle . track = 1 ;
this . setStatus ( 'Subtitles enabled.' ) ;
}
}
, setStatus : function ( txt ) {
$ ( '#' + this . stat )
. html ( txt )
. show ( 'slow' )
. delay ( 5000 )
. hide ( 'slow' ) ;
}
, setSpeed : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
if ( plugin . input . rate == 1 )
this . setPlaying ( true ) ;
else
this . setPlaying ( false ) ;
$ ( '#' + this . speed ) . html (
' x' + plugin . input . rate + ' ' ) ;
this . setStatus ( 'Set speed to x' + plugin . input . rate ) ;
}
, faster : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
if ( plugin . input . rate < 8 )
plugin . input . rate *= 2 ;
this . setSpeed ( ) ;
}
, slower : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
if ( plugin . input . rate > 1 )
plugin . input . rate /= 2 ;
this . setSpeed ( ) ;
}
2012-01-25 23:19:57 +00:00
, togglePlay : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
if ( plugin . playlist . isPlaying ) {
2012-07-16 20:29:59 +00:00
if ( plugin . input . rate != 1 )
{
plugin . input . rate = 1 ;
this . setSpeed ( ) ;
}
else
plugin . playlist . togglePause ( ) ;
2012-01-25 23:19:57 +00:00
}
else {
plugin . playlist . play ( ) ;
}
this . statusCheckStart ( ) ;
}
, stop : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
plugin . playlist . stop ( ) ;
//this.statusCheckStop();
// timeout to ensure to get last events
setTimeout ( "VLCobject.getInstance('" + this . playerId + "').statusCheckStop();" , 1000 ) ;
}
, options : {
set : function ( name , value ) {
this . items [ name ] = value || null ;
}
, del : function ( name ) {
delete this . items [ name ] ;
}
, clear : function ( ) {
this . items = new Array ( ) ;
}
// internal use only
, items : { }
, get : function ( ) {
var tmp _array = new Array ( ) ;
var debug _str = "" ;
var idx = 0 ;
for ( var i in this . items )
{
var option _str = ":" + i ;
if ( this . items [ i ] ) option _str += "=" + this . items [ i ] ;
tmp _array [ idx ] = option _str ;
debug _str += option _str + " " ;
idx += 1 ;
}
if ( document . all ) return tmp _array ;
return debug _str ;
}
}
// private status stuff
, VLC _STATUS : {
0 : 'standby'
, 1 : 'opening'
, 2 : 'buffering'
, 3 : 'playing'
, 4 : 'paused'
, 5 : 'stopped'
, 6 : 'ended'
}
, statusChanged : function ( ) {
if ( ! this . status ) {
this . setStatusText ( this . VLC _STATUS [ 0 ] ) ;
var width = this . getSliderLength ( ) ;
var tb = $ ( '#' + this . playerId + '_toolbar_slider' ) ;
tb . width ( width ) ;
return ;
}
if ( this . status == 3 ) {
// playing
//if(!this.sliderCreated) this.setStatusText('playing');
this . setPlaying ( true ) ;
}
else {
this . setPlaying ( false ) ;
if ( this . sliderCreated && this . status != 4 ) {
this . updateSlider ( 0 ) ;
}
if ( ( this . status == 0 || this . status == 5 || this . status == 6 ) ) {
this . setStatusText ( this . VLC _STATUS [ this . status ] ) ;
this . sliderCreated = false ;
}
}
if ( ! this . sliderCreated ) this . setStatusText ( this . VLC _STATUS [ this . status ] ) ;
return ;
}
, setPlaying : function ( playing ) {
var tgt = $ ( '#' + this . playerId + '_toolbar_btn0' ) ;
if ( playing ) {
tgt . removeClass ( 'x-vlc-btn-play' ) ;
tgt . addClass ( 'x-vlc-btn-pause' ) ;
if ( ! this . sliderCreated ) this . setStatusText ( 'playing' ) ;
}
else {
tgt . removeClass ( 'x-vlc-btn-pause' ) ;
tgt . addClass ( 'x-vlc-btn-play' ) ;
if ( ! this . sliderCreated ) this . setStatusText ( 'paused' ) ;
}
}
, statusCheck : function ( ) {
var plugin = this . _ _getPlugin ( ) ;
if ( ! plugin . input ) return ;
var status = plugin . input . state ;
if ( status != this . status ) {
this . status = status ;
this . statusChanged ( ) ;
}
if ( plugin . playlist . isPlaying ) {
2012-07-16 20:29:59 +00:00
2012-01-25 23:19:57 +00:00
this . updatePosition ( plugin . input . time / 1000 , plugin . input . length / 1000 )
}
}
, statusCheckStart : function ( ) {
this . statusCheckStop ( ) ;
this . statusCheckTimer = setInterval ( "VLCobject.getInstance('" + this . playerId + "').statusCheck();" , 300 ) ;
}
, statusCheckStop : function ( ) {
clearTimeout ( this . statusCheckTimer ) ;
}
, secsToTime : function ( secs ) {
if ( secs == 0 ) {
return '00:00'
}
var secs = parseInt ( secs ) ;
var mins = 0 ;
if ( secs > 60 ) {
mins = Math . floor ( secs / 60 ) ;
secs = parseInt ( ( secs - ( mins * 60 ) ) ) ;
}
return this . pad ( mins , 2 ) + ':' + this . pad ( secs , 2 ) ;
}
, pad : function ( number , length ) {
var str = '' + number ;
while ( str . length < length ) {
str = '0' + str ;
}
return str ;
}
, getSliderLength : function ( ) {
var l = ( $ ( '#' + this . plugin ) . width ( ) - ( 105 + 100 ) ) ;
return l ;
}
, updateSlider : function ( percentage ) {
2012-07-16 20:29:59 +00:00
return ;
2012-01-25 23:19:57 +00:00
var td1 = $ ( '#' + this . slider + ' :first-child :first-child :first-child' ) ;
var td3 = $ ( '#' + this . slider + ' :first-child :first-child :last-child' ) ;
var offset = this . getSliderLength ( ) ;
var w = offset * percentage ;
td1 . width ( w ) ;
w = offset * ( 1 - percentage ) ;
td3 . width ( w ) ;
}
, setStatusText : function ( txt ) {
this . sliderCreated = false ;
var tb = $ ( '#' + this . playerId + '_toolbar_slider' ) ;
tb . html ( txt ) ;
}
, updatePosition : function ( position , length ) {
2012-07-16 20:29:59 +00:00
return ;
2012-01-25 23:19:57 +00:00
// update timer
$ ( '#' + this . timer ) . html ( this . secsToTime ( position ) + '/' + this . secsToTime ( length ) ) ;
var tb = $ ( '#' + this . playerId + '_toolbar_slider' ) ;
if ( length == 0 ) {
//var width = ($('#'+this.plugin).width() - 4 - 50 - $('#'+this.timer).width() );
var width = this . getSliderLength ( ) ;
tb . width ( width ) ;
this . sliderCreated = false
if ( position < 1 ) this . statusChanged ( ) ; // force display stattus at startup
}
else {
this . createSlider ( ) ;
this . updateSlider ( position / length ) ;
}
}
// UI
, onSliderClick : function ( event ) {
var slider = $ ( '#' + event . data . instance . slider ) ;
var x = event . pageX ;
var y = event . pageY ;
var x _offset = x - slider . position ( ) . left ;
var percentage = x _offset * 100 / slider . width ( ) ;
event . data . instance . updateSlider ( x _offset / slider . width ( ) ) ;
event . data . instance . seek ( percentage ) ;
}
, createSlider : function ( ) {
if ( $ ( '#' + slider _id ) . length > 0 && $ ( '#' + table _id ) . length > 0 ) return ;
var offset = this . getSliderLength ( ) ;
var slider _id = this . playerId + '_toolbar_slider' ;
var table _id = this . playerId + '_toolbar_slider_tb' ;
var progress = "<table id='" + table _id + "' border=0 style='margin-top:5px;height:10px;cursor:pointer;display:inline' cellpadding=0 cellspacing=0 ><tr ><td width='0' class='x-vlc-slider'></td><td class='x-vlc-slider-thumb'></td><td width='" + ( offset ) + "' class='x-vlc-slider'></td></tr></table>" ;
2012-07-16 20:29:59 +00:00
2012-01-25 23:19:57 +00:00
if ( $ ( '#' + slider _id ) . length == 0 ) {
// div not preset exists
var tgt = $ ( '#' + this . playerId + '_toolbar' ) ;
var slider = "<div id='" + slider _id + "' width='" + ( offset + 4 ) + "' style='text-align:center;float:left;height:10px'>" ;
//slider += progress
slider += "</div>" ;
tgt . append ( slider ) ;
$ ( '#' + slider _id ) . bind ( 'click' , { instance : this } , this . onSliderClick ) ;
}
if ( $ ( '#' + table _id ) . length == 0 ) {
var slider = $ ( '#' + slider _id ) ;
slider . html ( '' ) ;
slider . append ( progress ) ;
}
this . sliderCreated = true ;
}
}
return instance ;
}
if ( ! window . opera && document . all ) {
if ( ! VLCobject . unloadSet ) {
VLCobject . prepUnload = function ( ) {
_ _vlc _unloadHandler = function ( ) { } ;
_ _vlc _savedUnloadHandler = function ( ) { } ;
window . attachEvent ( "onunload" , VLCobject . cleanupVLCs ) ;
}
window . attachEvent ( "onbeforeunload" , VLCobject . prepUnload ) ;
VLCobject . unloadSet = true ;
}
}
VLCobject . cleanupVLCs = function ( ) {
for ( i in this . INSTANCES ) {
i . stop ( ) ;
}
var objects = document . getElementsByTagName ( "OBJECT" ) ;
for ( var i = objects . length - 1 ; i >= 0 ; i -- ) {
objects [ i ] . style . display = 'none' ;
for ( var x in objects [ i ] ) {
if ( typeof objects [ i ] [ x ] == 'function' ) {
objects [ i ] [ x ] = function ( ) { } ;
}
}
}
}