src/js/libs/popcorn.jwplayer.js
branchnew-model
changeset 883 d35ad8111c5e
parent 882 61c384dda19e
child 884 10233337f6da
equal deleted inserted replaced
882:61c384dda19e 883:d35ad8111c5e
     1 var jwplayerObjects = {};
       
     2 
       
     3 Popcorn.player( "jwplayer", {
       
     4   _setup: function( options ) {
       
     5 
       
     6     var media = this,
       
     7         player = {},
       
     8         container = document.createElement( "div" ),
       
     9         currentTime = 0,
       
    10         seekTime = 0,
       
    11         seeking = false,
       
    12         dataLoaded = false;
       
    13     container.id = media.id + Popcorn.guid();
       
    14 
       
    15     media.appendChild( container );
       
    16 
       
    17   var initApi = function () {
       
    18     jwplayer( container.id ).onTime(function() {
       
    19         currentTime = jwplayer(container.id).getPosition();
       
    20         media.dispatchEvent( "timeupdate" );
       
    21        // timeout = setTimeout( timeupdate, 10 );
       
    22     });
       
    23     
       
    24     media.play = function() {
       
    25       media.paused = false;
       
    26       media.dispatchEvent( "play" );
       
    27 
       
    28       media.dispatchEvent( "playing" );
       
    29       jwplayer( container.id ).play();
       
    30     };
       
    31     
       
    32     media.pause = function() {
       
    33 
       
    34       if ( !media.paused ) {
       
    35         media.paused = true;
       
    36         media.dispatchEvent( "pause" );
       
    37         jwplayer( container.id ).pause();
       
    38       }
       
    39     };
       
    40 
       
    41     Popcorn.player.defineProperty( media, "currentTime", {
       
    42           set: function( val ) {
       
    43             // make sure val is a number
       
    44             currentTime = seekTime = +val;
       
    45             seeking = true;
       
    46             media.dispatchEvent( "seeked" );
       
    47             media.dispatchEvent( "timeupdate" );
       
    48             jwplayer( container.id ).seek( currentTime );
       
    49             return currentTime;
       
    50           },
       
    51           get: function() {
       
    52             return jwplayer( container.id ).getPosition();            
       
    53           }
       
    54         });
       
    55  
       
    56     Popcorn.player.defineProperty( media, "muted", {   
       
    57         set: function( val ) {
       
    58           if ( jwplayer( container.id ).getMute() !== val ) {
       
    59             if ( val ) {
       
    60               jwplayer( container.id ).setMute(true);
       
    61             } else {
       
    62               jwplayer( container.id ).setMute(false);
       
    63             }
       
    64 
       
    65             media.dispatchEvent( "volumechange" );
       
    66           }
       
    67           
       
    68           return jwplayer( container.id ).getMute();
       
    69         },
       
    70         get: function() {
       
    71           return jwplayer( container.id ).getMute();
       
    72         }
       
    73     });
       
    74   
       
    75     Popcorn.player.defineProperty( media, "volume", {
       
    76     
       
    77       set: function( val ) {
       
    78 
       
    79         if ( jwplayer( container.id ).getVolume() !== val *100 ) {
       
    80           jwplayer( container.id ).setVolume( val * 100);
       
    81           media.dispatchEvent( "volumechange" );
       
    82         }
       
    83         
       
    84         return (jwplayer( container.id ).getVolume()) / 100;
       
    85       },
       
    86       
       
    87       get: function() {
       
    88         return jwplayer( container.id ).getVolume() / 100;
       
    89       }
       
    90     });
       
    91 
       
    92     media.readyState = 4;
       
    93     media.dispatchEvent( 'load' );
       
    94     dataLoaded = true;
       
    95 
       
    96     media.duration = options.duration;
       
    97     media.dispatchEvent( 'durationchange' );
       
    98 
       
    99     media.paused && media.dispatchEvent( 'loadeddata' );
       
   100 
       
   101     };
       
   102 
       
   103     options.events = {
       
   104         onReady: initApi
       
   105       };
       
   106       
       
   107     jwplayer( container.id ).setup(options);
       
   108 
       
   109   }
       
   110 });
       
   111