| author | durandn |
| Tue, 01 Sep 2015 15:57:54 +0200 | |
| changeset 1047 | c3bf174e0ef8 |
| parent 1044 | d8339b45edc4 |
| child 1068 | 7623f9af9272 |
| permissions | -rw-r--r-- |
| 958 | 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 |
||
| 959 | 7 |
/* A Popcorn-based player for HTML5 Video, Youtube and Vimeo */ |
8 |
||
| 958 | 9 |
IriSP.Widgets.PopcornPlayer.prototype.defaults = { |
| 1013 | 10 |
}; |
| 958 | 11 |
|
12 |
IriSP.Widgets.PopcornPlayer.prototype.draw = function() { |
|
| 979 | 13 |
|
| 958 | 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 |
|
|
| 959 | 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; |
|
| 967 | 41 |
if (this.autostart || this.autoplay) { |
42 |
_params.autoplay = 1; |
|
43 |
} |
|
| 959 | 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, |
|
| 987 | 57 |
height : this.height || undefined |
| 959 | 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); |
|
| 967 | 73 |
if (this.autostart || this.autoplay) { |
74 |
_popcorn.autoplay(true); |
|
75 |
} |
|
| 958 | 76 |
} |
| 967 | 77 |
|
| 970 | 78 |
var _media = this.media; |
79 |
|
|
| 958 | 80 |
// Binding functions to Popcorn |
81 |
|
|
| 970 | 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 |
}); |
|
| 958 | 103 |
|
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
104 |
_media.on("settimerange", function(_timeRange){ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
105 |
_media.timeRange = _timeRange; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
106 |
try { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
107 |
if (_media.getCurrentTime() > _timeRange[0] || _media.getCurrentTime() < _timeRange){ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
108 |
_popcorn.currentTime(_timeRange[0] / 1000); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
109 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
110 |
} catch (err) { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
111 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
112 |
}) |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
113 |
|
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
114 |
_media.on("resettimerange", function(){ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
115 |
_media.timeRange = false; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
116 |
}) |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
117 |
|
| 958 | 118 |
// Binding Popcorn events to media |
119 |
|
|
| 970 | 120 |
function getVolume() { |
121 |
_media.muted = _popcorn.muted(); |
|
122 |
_media.volume = _popcorn.volume(); |
|
123 |
} |
|
124 |
|
|
125 |
_popcorn.on("loadedmetadata", function() { |
|
126 |
getVolume(); |
|
127 |
_media.trigger("loadedmetadata"); |
|
128 |
_media.trigger("volumechange"); |
|
| 1013 | 129 |
}); |
| 970 | 130 |
|
| 958 | 131 |
_popcorn.on("timeupdate", function() { |
| 970 | 132 |
_media.trigger("timeupdate", new IriSP.Model.Time(1000*_popcorn.currentTime())); |
| 958 | 133 |
}); |
134 |
|
|
| 970 | 135 |
_popcorn.on("volumechange", function() { |
136 |
getVolume(); |
|
137 |
_media.trigger("volumechange"); |
|
| 1013 | 138 |
}); |
| 958 | 139 |
|
| 970 | 140 |
_popcorn.on("play", function() { |
141 |
_media.trigger("play"); |
|
142 |
}); |
|
143 |
|
|
144 |
_popcorn.on("pause", function() { |
|
145 |
_media.trigger("pause"); |
|
146 |
}); |
|
147 |
|
|
148 |
_popcorn.on("seeked", function() { |
|
149 |
_media.trigger("seeked"); |
|
150 |
}); |
|
| 958 | 151 |
|
| 1013 | 152 |
}; |