src/widgets/DailymotionPlayer.js
changeset 1013 392ddcd212d7
parent 959 ee11ed1b739e
child 1068 7623f9af9272
equal deleted inserted replaced
1012:7e18d953a1f8 1013:392ddcd212d7
     4 
     4 
     5 IriSP.Widgets.DailymotionPlayer.prototype = new IriSP.Widgets.Widget();
     5 IriSP.Widgets.DailymotionPlayer.prototype = new IriSP.Widgets.Widget();
     6 
     6 
     7 IriSP.Widgets.DailymotionPlayer.prototype.defaults = {
     7 IriSP.Widgets.DailymotionPlayer.prototype.defaults = {
     8     aspect_ratio: 14/9
     8     aspect_ratio: 14/9
     9 }
     9 };
    10 
    10 
    11 IriSP.Widgets.DailymotionPlayer.prototype.draw = function() {
    11 IriSP.Widgets.DailymotionPlayer.prototype.draw = function() {
    12     
    12     
    13     if (typeof this.video === "undefined") {
    13     if (typeof this.video === "undefined") {
    14         this.video = this.media.video;
    14         this.video = this.media.video;
    28 
    28 
    29         var _player = document.getElementById(_this.container);
    29         var _player = document.getElementById(_this.container);
    30         
    30         
    31         _media.getCurrentTime = function() {
    31         _media.getCurrentTime = function() {
    32             return new IriSP.Model.Time(1000*_player.getCurrentTime());
    32             return new IriSP.Model.Time(1000*_player.getCurrentTime());
    33         }
    33         };
    34         _media.getVolume = function() {
    34         _media.getVolume = function() {
    35             return _player.getVolume() / 100;
    35             return _player.getVolume() / 100;
    36         }
    36         };
    37         _media.getPaused = function() {
    37         _media.getPaused = function() {
    38             return _pauseState;
    38             return _pauseState;
    39         }
    39         };
    40         _media.getMuted = function() {
    40         _media.getMuted = function() {
    41             return _player.isMuted();
    41             return _player.isMuted();
    42         }
    42         };
    43         _media.setCurrentTime = function(_milliseconds) {
    43         _media.setCurrentTime = function(_milliseconds) {
    44             _seekPause = _pauseState;
    44             _seekPause = _pauseState;
    45             return _player.seekTo(_milliseconds / 1000);
    45             return _player.seekTo(_milliseconds / 1000);
    46         }
    46         };
    47         _media.setVolume = function(_vol) {
    47         _media.setVolume = function(_vol) {
    48             return _player.setVolume(Math.floor(_vol*100));
    48             return _player.setVolume(Math.floor(_vol*100));
    49         }
    49         };
    50         _media.mute = function() {
    50         _media.mute = function() {
    51             return _player.mute();
    51             return _player.mute();
    52         }
    52         };
    53         _media.unmute = function() {
    53         _media.unmute = function() {
    54             return _player.unMute();
    54             return _player.unMute();
    55         }
    55         };
    56         _media.play = function() {
    56         _media.play = function() {
    57             return _player.playVideo();
    57             return _player.playVideo();
    58         }
    58         };
    59         _media.pause = function() {
    59         _media.pause = function() {
    60             return _player.pauseVideo();
    60             return _player.pauseVideo();
    61         }
    61         };
    62         
    62         
    63         _player.addEventListener("onStateChange", "onDailymotionStateChange");
    63         _player.addEventListener("onStateChange", "onDailymotionStateChange");
    64         _player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
    64         _player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
    65         
    65         
    66         _player.cueVideoByUrl(_this.video);
    66         _player.cueVideoByUrl(_this.video);
    67         
    67         
    68         _media.trigger("loadedmetadata");
    68         _media.trigger("loadedmetadata");
    69     }
    69     };
    70     
    70     
    71     window.onDailymotionStateChange = function(_state) {
    71     window.onDailymotionStateChange = function(_state) {
    72         switch(_state) {
    72         switch(_state) {
    73             case 1:
    73             case 1:
    74                 _media.trigger("play");
    74                 _media.trigger("play");
    82     
    82     
    83             case 3:
    83             case 3:
    84                 _media.trigger("seeked");
    84                 _media.trigger("seeked");
    85                 break;
    85                 break;
    86         }
    86         }
    87     }
    87     };
    88     
    88     
    89     window.onDailymotionVideoProgress = function(_progress) {
    89     window.onDailymotionVideoProgress = function(_progress) {
    90         _media.trigger("timeupdate", new IriSP.Model.Time(_progress.mediaTime * 1000));
    90         _media.trigger("timeupdate", new IriSP.Model.Time(_progress.mediaTime * 1000));
    91     }
    91     };
    92     
    92     
    93     var params = {
    93     var params = {
    94         "allowScriptAccess" : "always",
    94         "allowScriptAccess" : "always",
    95         "wmode": "opaque"
    95         "wmode": "opaque"
    96     };
    96     };
    99         id : this.container
    99         id : this.container
   100     };
   100     };
   101 
   101 
   102     swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, this.width, this.height, "8", null, null, params, atts);
   102     swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, this.width, this.height, "8", null, null, params, atts);
   103     
   103     
   104 }
   104 };