2 IriSP.Widgets.Widget.call(this, player, config); |
2 IriSP.Widgets.Widget.call(this, player, config); |
3 }; |
3 }; |
4 |
4 |
5 IriSP.Widgets.PopcornPlayer.prototype = new IriSP.Widgets.Widget(); |
5 IriSP.Widgets.PopcornPlayer.prototype = new IriSP.Widgets.Widget(); |
6 |
6 |
|
7 /* A Popcorn-based player for HTML5 Video, Youtube and Vimeo */ |
|
8 |
7 IriSP.Widgets.PopcornPlayer.prototype.defaults = { |
9 IriSP.Widgets.PopcornPlayer.prototype.defaults = { |
|
10 aspect_ratio: 14/9 |
8 } |
11 } |
9 |
12 |
10 IriSP.Widgets.PopcornPlayer.prototype.draw = function() { |
13 IriSP.Widgets.PopcornPlayer.prototype.draw = function() { |
11 var _tmpId = Popcorn.guid("video"), |
14 |
12 _videoEl = IriSP.jQuery('<video>'); |
|
13 |
15 |
14 if (typeof this.video === "undefined") { |
16 if (typeof this.video === "undefined") { |
15 this.video = this.media.video; |
17 this.video = this.media.video; |
16 } |
18 } |
17 |
19 |
18 if (this.url_transform) { |
20 if (this.url_transform) { |
19 this.video = this.url_transform(this.video); |
21 this.video = this.url_transform(this.video); |
20 } |
22 } |
21 |
23 |
22 _videoEl.attr({ |
24 if (!this.height) { |
23 "src" : this.video, |
25 this.height = Math.floor(this.width/this.aspect_ratio); |
24 "id" : _tmpId |
26 this.$.css({ |
25 }) |
27 height: this.height |
26 |
28 }); |
27 if(this.width) { |
|
28 _videoEl.attr("width", this.width); |
|
29 } |
29 } |
30 if(this.height) { |
30 |
31 _videoEl.attr("height", this.height); |
31 if (/^(https?:\/\/)?(www\.)?vimeo\.com/.test(this.video)) { |
|
32 |
|
33 /* VIMEO */ |
|
34 |
|
35 var _popcorn = Popcorn.vimeo(this.container, this.video); |
|
36 |
|
37 } else if (/^(https?:\/\/)?(www\.)?youtube\.com/.test(this.video)) { |
|
38 |
|
39 /* YOUTUBE */ |
|
40 |
|
41 var _urlparts = this.video.split(/[?&]/), |
|
42 _params = {}; |
|
43 for (var i = 1; i < _urlparts.length; i++) { |
|
44 var _ppart = _urlparts[i].split('='); |
|
45 _params[_ppart[0]] = decodeURIComponent(_ppart[1]); |
|
46 } |
|
47 _params.controls = 0; |
|
48 _params.modestbranding = 1; |
|
49 _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params); |
|
50 |
|
51 var _popcorn = Popcorn.youtube(this.container, _url); |
|
52 |
|
53 } else { |
|
54 |
|
55 /* DEFAULT HTML5 */ |
|
56 |
|
57 var _tmpId = IriSP._.uniqueId("popcorn"), |
|
58 _videoEl = IriSP.jQuery('<video>'); |
|
59 _videoEl.attr({ |
|
60 id : _tmpId, |
|
61 width : this.width, |
|
62 height : this.height |
|
63 }); |
|
64 if(typeof this.video === "string"){ |
|
65 _videoEl.attr("src",this.video); |
|
66 } else { |
|
67 for (var i = 0; i < this.video.length; i++) { |
|
68 var _srcNode = IriSP.jQuery('<source>'); |
|
69 _srcNode.attr({ |
|
70 src: this.video[i].src, |
|
71 type: this.video[i].type |
|
72 }); |
|
73 _videoEl.append(_srcNode); |
|
74 } |
|
75 } |
|
76 this.$.html(_videoEl); |
|
77 var _popcorn = Popcorn("#" + _tmpId); |
32 } |
78 } |
33 this.$.append(_videoEl); |
|
34 var _popcorn = Popcorn("#" + _tmpId); |
|
35 |
79 |
36 // Binding functions to Popcorn |
80 // Binding functions to Popcorn |
37 |
81 |
38 this.media.getCurrentTime = function() { |
82 this.media.getCurrentTime = function() { |
39 return new IriSP.Model.Time(1000*_popcorn.currentTime()); |
83 return new IriSP.Model.Time(1000*_popcorn.currentTime()); |