src/widgets/HtmlPlayer.js
changeset 986 f9d51dd4a3fe
child 987 7b65bf78873a
equal deleted inserted replaced
985:9859c4bae904 986:f9d51dd4a3fe
       
     1 IriSP.Widgets.HtmlPlayer = function(player, config) {
       
     2     IriSP.Widgets.Widget.call(this, player, config);
       
     3 };
       
     4 
       
     5 IriSP.Widgets.HtmlPlayer.prototype = new IriSP.Widgets.Widget();
       
     6 
       
     7 
       
     8 IriSP.Widgets.HtmlPlayer.prototype.defaults = {
       
     9     aspect_ratio: 14/9
       
    10 }
       
    11 
       
    12 IriSP.Widgets.HtmlPlayer.prototype.draw = function() {
       
    13 
       
    14     
       
    15     if (typeof this.video === "undefined") {
       
    16         this.video = this.media.video;
       
    17     }
       
    18     
       
    19     if (this.url_transform) {
       
    20         this.video = this.url_transform(this.video);
       
    21     }
       
    22     
       
    23     if (!this.height) {
       
    24         this.height = Math.floor(this.width/this.aspect_ratio);
       
    25         this.$.css({
       
    26                 height: this.height
       
    27             });
       
    28     }
       
    29         
       
    30     var videoEl = IriSP.jQuery('<video>');
       
    31     videoEl.attr({
       
    32         id : _tmpId,
       
    33         width : this.width,
       
    34         height : this.height
       
    35     });
       
    36     if(typeof this.video === "string"){
       
    37         videoEl.attr("src",this.video);
       
    38     } else {
       
    39         for (var i = 0; i < this.video.length; i++) {
       
    40             var _srcNode = IriSP.jQuery('<source>');
       
    41             _srcNode.attr({
       
    42                 src: this.video[i].src,
       
    43                 type: this.video[i].type
       
    44             });
       
    45             videoEl.append(_srcNode);
       
    46         }
       
    47     }
       
    48     this.$.html(videoEl);
       
    49     if (this.autostart || this.autoplay) {
       
    50         videoEl.attr("autoplay", true);
       
    51     }
       
    52     
       
    53     var mediaEl = videoEl[0],
       
    54         media = this.media;
       
    55     
       
    56     // Binding functions to Popcorn
       
    57     media.on("setcurrenttime", function(_milliseconds) {
       
    58         try {
       
    59             mediaEl.currentTime = (_milliseconds / 1000);
       
    60         } catch (err) {
       
    61             
       
    62         }
       
    63     });
       
    64     
       
    65     media.on("setvolume", function(_vol) {
       
    66         media.volume = _vol;
       
    67         try {
       
    68             mediaEl.volume = _vol;
       
    69         } catch (err) {
       
    70             
       
    71         }
       
    72     });
       
    73     
       
    74     media.on("setmuted", function(_muted) {
       
    75         media.muted = _muted;
       
    76         try {
       
    77             mediaEl.muted = _muted;
       
    78         } catch (err) {
       
    79             
       
    80         }
       
    81     });
       
    82     
       
    83     media.on("setplay", function() {
       
    84         try {
       
    85             mediaEl.play();
       
    86         } catch (err) {
       
    87             
       
    88         }
       
    89     });
       
    90     
       
    91     media.on("setpause", function() {
       
    92         try {
       
    93             mediaEl.pause();
       
    94         } catch (err) {
       
    95             
       
    96         }
       
    97     });
       
    98     
       
    99     // Binding Popcorn events to media
       
   100     function getVolume() {
       
   101         media.muted = mediaEl.muted;
       
   102         media.volume = mediaEl.volume;
       
   103     }
       
   104     
       
   105     videoEl.on("loadedmetadata", function() {
       
   106         getVolume();
       
   107         media.trigger("loadedmetadata");
       
   108         media.trigger("volumechange");
       
   109     })
       
   110     
       
   111     videoEl.on("timeupdate", function() {
       
   112         media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime));
       
   113     });
       
   114     
       
   115     videoEl.on("volumechange", function() {
       
   116         getVolume();
       
   117         media.trigger("volumechange");
       
   118     })
       
   119     
       
   120     videoEl.on("play", function() {
       
   121         media.trigger("play");
       
   122     });
       
   123     
       
   124     videoEl.on("pause", function() {
       
   125         media.trigger("pause");
       
   126     });
       
   127     
       
   128     videoEl.on("seeking", function() {
       
   129         media.trigger("seeking");
       
   130     });
       
   131     
       
   132     videoEl.on("seeked", function() {
       
   133         media.trigger("seeked");
       
   134     });
       
   135     
       
   136 }