web/res/metadataplayer/PopcornPlayer.js
changeset 1558 761ba7426984
parent 1557 7c67caaafdeb
child 1559 796b49572291
equal deleted inserted replaced
1557:7c67caaafdeb 1558:761ba7426984
     1 IriSP.Widgets.PopcornPlayer = function(player, config) {
       
     2     IriSP.Widgets.Widget.call(this, player, config);
       
     3 };
       
     4 
       
     5 IriSP.Widgets.PopcornPlayer.prototype = new IriSP.Widgets.Widget();
       
     6 
       
     7 /* A Popcorn-based player for HTML5 Video, Youtube and Vimeo */
       
     8 
       
     9 IriSP.Widgets.PopcornPlayer.prototype.defaults = {
       
    10 };
       
    11 
       
    12 IriSP.Widgets.PopcornPlayer.prototype.draw = function() {
       
    13     if (typeof this.video === "undefined") {
       
    14         this.video = this.media.video;
       
    15     }
       
    16 
       
    17     if (this.url_transform) {
       
    18         this.video = this.url_transform(this.video);
       
    19     }
       
    20 
       
    21     var _url = this.video;
       
    22 
       
    23     if (/^(https?:\/\/)?(www\.)?youtube\.com/.test(this.video)) {
       
    24         /* YOUTUBE */
       
    25         var _urlparts = this.video.split(/[?&]/),
       
    26             _params = {};
       
    27         for (var i = 1; i < _urlparts.length; i++) {
       
    28             var _ppart = _urlparts[i].split('=');
       
    29             _params[_ppart[0]] = decodeURIComponent(_ppart[1]);
       
    30         }
       
    31         _params.controls = 0;
       
    32         _params.modestbranding = 1;
       
    33         if (this.autostart || this.autoplay) {
       
    34             _params.autoplay = 1;
       
    35         }
       
    36         _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params);
       
    37 
       
    38     }// else {
       
    39     //     /* DEFAULT HTML5 */
       
    40     //     var _tmpId = IriSP._.uniqueId("popcorn"),
       
    41     //         _videoEl = IriSP.jQuery('<video>');
       
    42     //     _videoEl.attr({
       
    43     //         id : _tmpId,
       
    44     //         width : this.width,
       
    45     //         height : this.height || undefined
       
    46     //     });
       
    47     //     if(typeof this.video === "string"){
       
    48     //         _videoEl.attr("src",this.video);
       
    49     //     } else {
       
    50     //         for (var i = 0; i < this.video.length; i++) {
       
    51     //             var _srcNode = IriSP.jQuery('<source>');
       
    52     //             _srcNode.attr({
       
    53     //                 src: this.video[i].src,
       
    54     //                 type: this.video[i].type
       
    55     //             });
       
    56     //             _videoEl.append(_srcNode);
       
    57     //         }
       
    58     //     }
       
    59     //     this.$.html(_videoEl);
       
    60     // }
       
    61 
       
    62     var _popcorn = Popcorn.smart("#"+this.container, _url);
       
    63 
       
    64     if (this.autostart || this.autoplay) {
       
    65         _popcorn.autoplay(true);
       
    66     }
       
    67 
       
    68     var _media = this.media;
       
    69 
       
    70     // Binding functions to Popcorn
       
    71 
       
    72     _media.on("setcurrenttime", function(_milliseconds) {
       
    73         _popcorn.currentTime(_milliseconds / 1000);
       
    74     });
       
    75 
       
    76     _media.on("setvolume", function(_vol) {
       
    77         _popcorn.volume(_vol);
       
    78         _media.volume = _vol;
       
    79     });
       
    80 
       
    81     _media.on("setmuted", function(_muted) {
       
    82         _popcorn.muted(_muted);
       
    83         _media.muted = _muted;
       
    84     });
       
    85 
       
    86     _media.on("setplay", function() {
       
    87         _popcorn.play();
       
    88     });
       
    89 
       
    90     _media.on("setpause", function() {
       
    91         _popcorn.pause();
       
    92     });
       
    93     _media.on("settimerange", function(_timeRange){
       
    94         _media.timeRange = _timeRange;
       
    95         try {
       
    96             if (_media.getCurrentTime() > _timeRange[0] || _media.getCurrentTime() < _timeRange){
       
    97                 _popcorn.currentTime(_timeRange[0] / 1000);
       
    98             }
       
    99         } catch (err) {
       
   100         }
       
   101     })
       
   102     _media.on("resettimerange", function(){
       
   103         _media.timeRange = false;
       
   104     })
       
   105     // Binding Popcorn events to media
       
   106 
       
   107     function getVolume() {
       
   108         _media.muted = _popcorn.muted();
       
   109         _media.volume = _popcorn.volume();
       
   110     }
       
   111 
       
   112     _popcorn.on("loadedmetadata", function() {
       
   113         getVolume();
       
   114         _media.trigger("loadedmetadata");
       
   115         _media.trigger("volumechange");
       
   116     });
       
   117 
       
   118     _popcorn.on("timeupdate", function() {
       
   119         _media.trigger("timeupdate", new IriSP.Model.Time(1000*_popcorn.currentTime()));
       
   120     });
       
   121 
       
   122     _popcorn.on("volumechange", function() {
       
   123         getVolume();
       
   124         _media.trigger("volumechange");
       
   125     });
       
   126 
       
   127     _popcorn.on("play", function(e) {
       
   128         _media.trigger("play");
       
   129     });
       
   130 
       
   131     _popcorn.on("pause", function() {
       
   132         _media.trigger("pause");
       
   133     });
       
   134 
       
   135     _popcorn.on("seeked", function() {
       
   136         _media.trigger("seeked");
       
   137     });
       
   138 
       
   139 };