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