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 |
|
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 (/^(https?:\/\/)?(www\.)?vimeo\.com/.test(this.video)) { |
|
24 |
|
25 /* VIMEO */ |
|
26 |
|
27 var _popcorn = Popcorn.vimeo(this.container, this.video); |
|
28 |
|
29 } else if (/^(https?:\/\/)?(www\.)?youtube\.com/.test(this.video)) { |
|
30 |
|
31 /* YOUTUBE */ |
|
32 |
|
33 var _urlparts = this.video.split(/[?&]/), |
|
34 _params = {}; |
|
35 for (var i = 1; i < _urlparts.length; i++) { |
|
36 var _ppart = _urlparts[i].split('='); |
|
37 _params[_ppart[0]] = decodeURIComponent(_ppart[1]); |
|
38 } |
|
39 _params.controls = 0; |
|
40 _params.modestbranding = 1; |
|
41 if (this.autostart || this.autoplay) { |
|
42 _params.autoplay = 1; |
|
43 } |
|
44 _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params); |
|
45 |
|
46 var _popcorn = Popcorn.youtube(this.container, _url); |
|
47 |
|
48 } else { |
|
49 |
|
50 /* DEFAULT HTML5 */ |
|
51 |
|
52 var _tmpId = IriSP._.uniqueId("popcorn"), |
|
53 _videoEl = IriSP.jQuery('<video>'); |
|
54 _videoEl.attr({ |
|
55 id : _tmpId, |
|
56 width : this.width, |
|
57 height : this.height || undefined |
|
58 }); |
|
59 if(typeof this.video === "string"){ |
|
60 _videoEl.attr("src",this.video); |
|
61 } else { |
|
62 for (var i = 0; i < this.video.length; i++) { |
|
63 var _srcNode = IriSP.jQuery('<source>'); |
|
64 _srcNode.attr({ |
|
65 src: this.video[i].src, |
|
66 type: this.video[i].type |
|
67 }); |
|
68 _videoEl.append(_srcNode); |
|
69 } |
|
70 } |
|
71 this.$.html(_videoEl); |
|
72 var _popcorn = Popcorn("#" + _tmpId); |
|
73 if (this.autostart || this.autoplay) { |
|
74 _popcorn.autoplay(true); |
|
75 } |
|
76 } |
|
77 |
|
78 var _media = this.media; |
|
79 |
|
80 // Binding functions to Popcorn |
|
81 |
|
82 _media.on("setcurrenttime", function(_milliseconds) { |
|
83 _popcorn.currentTime(_milliseconds / 1000); |
|
84 }); |
|
85 |
|
86 _media.on("setvolume", function(_vol) { |
|
87 _popcorn.volume(_vol); |
|
88 _media.volume = _vol; |
|
89 }); |
|
90 |
|
91 _media.on("setmuted", function(_muted) { |
|
92 _popcorn.muted(_muted); |
|
93 _media.muted = _muted; |
|
94 }); |
|
95 |
|
96 _media.on("setplay", function() { |
|
97 _popcorn.play(); |
|
98 }); |
|
99 |
|
100 _media.on("setpause", function() { |
|
101 _popcorn.pause(); |
|
102 }); |
|
103 |
|
104 // Binding Popcorn events to media |
|
105 |
|
106 function getVolume() { |
|
107 _media.muted = _popcorn.muted(); |
|
108 _media.volume = _popcorn.volume(); |
|
109 } |
|
110 |
|
111 _popcorn.on("loadedmetadata", function() { |
|
112 getVolume(); |
|
113 _media.trigger("loadedmetadata"); |
|
114 _media.trigger("volumechange"); |
|
115 }); |
|
116 |
|
117 _popcorn.on("timeupdate", function() { |
|
118 _media.trigger("timeupdate", new IriSP.Model.Time(1000*_popcorn.currentTime())); |
|
119 }); |
|
120 |
|
121 _popcorn.on("volumechange", function() { |
|
122 getVolume(); |
|
123 _media.trigger("volumechange"); |
|
124 }); |
|
125 |
|
126 _popcorn.on("play", function() { |
|
127 _media.trigger("play"); |
|
128 }); |
|
129 |
|
130 _popcorn.on("pause", function() { |
|
131 _media.trigger("pause"); |
|
132 }); |
|
133 |
|
134 _popcorn.on("seeked", function() { |
|
135 _media.trigger("seeked"); |
|
136 }); |
|
137 |
|
138 }; |
|