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