src/widgets/PopcornPlayer.js
changeset 1068 7623f9af9272
parent 1044 d8339b45edc4
child 1069 2409cb4cebaf
equal deleted inserted replaced
1067:539c9bee5372 1068:7623f9af9272
     8 
     8 
     9 IriSP.Widgets.PopcornPlayer.prototype.defaults = {
     9 IriSP.Widgets.PopcornPlayer.prototype.defaults = {
    10 };
    10 };
    11 
    11 
    12 IriSP.Widgets.PopcornPlayer.prototype.draw = function() {
    12 IriSP.Widgets.PopcornPlayer.prototype.draw = function() {
    13 
       
    14     
       
    15     if (typeof this.video === "undefined") {
    13     if (typeof this.video === "undefined") {
    16         this.video = this.media.video;
    14         this.video = this.media.video;
    17     }
    15     }
    18     
    16 
    19     if (this.url_transform) {
    17     if (this.url_transform) {
    20         this.video = this.url_transform(this.video);
    18         this.video = this.url_transform(this.video);
    21     }
    19     }
    22     
    20 
    23     if (/^(https?:\/\/)?(www\.)?vimeo\.com/.test(this.video)) {
    21     if (/^(https?:\/\/)?(www\.)?vimeo\.com/.test(this.video)) {
    24         
       
    25         /* VIMEO */
    22         /* VIMEO */
    26         
       
    27         var _popcorn = Popcorn.vimeo(this.container, this.video);
    23         var _popcorn = Popcorn.vimeo(this.container, this.video);
    28         
       
    29     } else if (/^(https?:\/\/)?(www\.)?youtube\.com/.test(this.video)) {
    24     } else if (/^(https?:\/\/)?(www\.)?youtube\.com/.test(this.video)) {
    30         
       
    31         /* YOUTUBE */
    25         /* YOUTUBE */
    32        
       
    33         var _urlparts = this.video.split(/[?&]/),
    26         var _urlparts = this.video.split(/[?&]/),
    34             _params = {};
    27             _params = {};
    35         for (var i = 1; i < _urlparts.length; i++) {
    28         for (var i = 1; i < _urlparts.length; i++) {
    36             var _ppart = _urlparts[i].split('=');
    29             var _ppart = _urlparts[i].split('=');
    37             _params[_ppart[0]] = decodeURIComponent(_ppart[1]);
    30             _params[_ppart[0]] = decodeURIComponent(_ppart[1]);
    40         _params.modestbranding = 1;
    33         _params.modestbranding = 1;
    41         if (this.autostart || this.autoplay) {
    34         if (this.autostart || this.autoplay) {
    42             _params.autoplay = 1;
    35             _params.autoplay = 1;
    43         }
    36         }
    44         _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params);
    37         _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params);
    45         
    38 
    46         var _popcorn = Popcorn.youtube(this.container, _url);
    39         var _popcorn = Popcorn.youtube(this.container, _url);
    47         
    40 
    48     } else {
    41     } else {
    49         
       
    50         /* DEFAULT HTML5 */
    42         /* DEFAULT HTML5 */
    51         
       
    52         var _tmpId = IriSP._.uniqueId("popcorn"),
    43         var _tmpId = IriSP._.uniqueId("popcorn"),
    53             _videoEl = IriSP.jQuery('<video>');
    44             _videoEl = IriSP.jQuery('<video>');
    54         _videoEl.attr({
    45         _videoEl.attr({
    55             id : _tmpId,
    46             id : _tmpId,
    56             width : this.width,
    47             width : this.width,
    72         var _popcorn = Popcorn("#" + _tmpId);
    63         var _popcorn = Popcorn("#" + _tmpId);
    73         if (this.autostart || this.autoplay) {
    64         if (this.autostart || this.autoplay) {
    74             _popcorn.autoplay(true);
    65             _popcorn.autoplay(true);
    75         }
    66         }
    76     }
    67     }
    77     
    68 
    78     var _media = this.media;
    69     var _media = this.media;
    79     
    70 
    80     // Binding functions to Popcorn
    71     // Binding functions to Popcorn
    81     
    72 
    82     _media.on("setcurrenttime", function(_milliseconds) {
    73     _media.on("setcurrenttime", function(_milliseconds) {
    83         _popcorn.currentTime(_milliseconds / 1000);
    74         _popcorn.currentTime(_milliseconds / 1000);
    84     });
    75     });
    85     
    76 
    86     _media.on("setvolume", function(_vol) {
    77     _media.on("setvolume", function(_vol) {
    87         _popcorn.volume(_vol);
    78         _popcorn.volume(_vol);
    88         _media.volume = _vol;
    79         _media.volume = _vol;
    89     });
    80     });
    90     
    81 
    91     _media.on("setmuted", function(_muted) {
    82     _media.on("setmuted", function(_muted) {
    92         _popcorn.muted(_muted);
    83         _popcorn.muted(_muted);
    93         _media.muted = _muted;
    84         _media.muted = _muted;
    94     });
    85     });
    95     
    86 
    96     _media.on("setplay", function() {
    87     _media.on("setplay", function() {
    97         _popcorn.play();
    88         _popcorn.play();
    98     });
    89     });
    99     
    90 
   100     _media.on("setpause", function() {
    91     _media.on("setpause", function() {
   101         _popcorn.pause();
    92         _popcorn.pause();
   102     });
    93     });
   103     
       
   104     _media.on("settimerange", function(_timeRange){
    94     _media.on("settimerange", function(_timeRange){
   105         _media.timeRange = _timeRange;
    95         _media.timeRange = _timeRange;
   106         try {
    96         try {
   107             if (_media.getCurrentTime() > _timeRange[0] || _media.getCurrentTime() < _timeRange){
    97             if (_media.getCurrentTime() > _timeRange[0] || _media.getCurrentTime() < _timeRange){
   108                 _popcorn.currentTime(_timeRange[0] / 1000);
    98                 _popcorn.currentTime(_timeRange[0] / 1000);
   109             }
    99             }
   110         } catch (err) {
   100         } catch (err) {
   111         }
   101         }
   112     })
   102     })
   113     
       
   114     _media.on("resettimerange", function(){
   103     _media.on("resettimerange", function(){
   115         _media.timeRange = false;
   104         _media.timeRange = false;
   116     })
   105     })
   117     
       
   118     // Binding Popcorn events to media
   106     // Binding Popcorn events to media
   119     
   107 
   120     function getVolume() {
   108     function getVolume() {
   121         _media.muted = _popcorn.muted();
   109         _media.muted = _popcorn.muted();
   122         _media.volume = _popcorn.volume();
   110         _media.volume = _popcorn.volume();
   123     }
   111     }
   124     
   112 
   125     _popcorn.on("loadedmetadata", function() {
   113     _popcorn.on("loadedmetadata", function() {
   126         getVolume();
   114         getVolume();
   127         _media.trigger("loadedmetadata");
   115         _media.trigger("loadedmetadata");
   128         _media.trigger("volumechange");
   116         _media.trigger("volumechange");
   129     });
   117     });
   130     
   118 
   131     _popcorn.on("timeupdate", function() {
   119     _popcorn.on("timeupdate", function() {
   132         _media.trigger("timeupdate", new IriSP.Model.Time(1000*_popcorn.currentTime()));
   120         _media.trigger("timeupdate", new IriSP.Model.Time(1000*_popcorn.currentTime()));
   133     });
   121     });
   134     
   122 
   135     _popcorn.on("volumechange", function() {
   123     _popcorn.on("volumechange", function() {
   136         getVolume();
   124         getVolume();
   137         _media.trigger("volumechange");
   125         _media.trigger("volumechange");
   138     });
   126     });
   139     
   127 
   140     _popcorn.on("play", function() {
   128     _popcorn.on("play", function() {
   141         _media.trigger("play");
   129         _media.trigger("play");
   142     });
   130     });
   143     
   131 
   144     _popcorn.on("pause", function() {
   132     _popcorn.on("pause", function() {
   145         _media.trigger("pause");
   133         _media.trigger("pause");
   146     });
   134     });
   147     
   135 
   148     _popcorn.on("seeked", function() {
   136     _popcorn.on("seeked", function() {
   149         _media.trigger("seeked");
   137         _media.trigger("seeked");
   150     });
   138     });
   151     
   139 
   152 };
   140 };