| author | durandn |
| Tue, 01 Sep 2015 15:10:17 +0200 | |
| changeset 1044 | d8339b45edc4 |
| parent 1013 | 392ddcd212d7 |
| child 1068 | 7623f9af9272 |
| permissions | -rw-r--r-- |
| 998 | 1 |
/* HTML player, to be reused in a widget, or elsewhere */ |
2 |
||
3 |
IriSP.htmlPlayer = function(media, jqselector, options) { |
|
4 |
|
|
5 |
var opts = options || {}, |
|
6 |
videoURL = opts.video || media.video; |
|
7 |
|
|
8 |
if (typeof opts.url_transform === "function") { |
|
9 |
videoURL = opts.url_transform(videoURL); |
|
10 |
} |
|
11 |
|
|
12 |
var videoEl = IriSP.jQuery('<video>'); |
|
13 |
|
|
14 |
videoEl.attr({ |
|
15 |
width : opts.width || undefined, |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
16 |
height : opts.height || undefined, |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
17 |
controls : opts.controls || undefined, |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
18 |
autoplay : opts.autostart || opts.autoplay || undefined |
| 998 | 19 |
}); |
20 |
|
|
21 |
if(typeof videoURL === "string"){ |
|
22 |
videoEl.attr("src",videoURL); |
|
23 |
} else { |
|
24 |
for (var i = 0; i < videoURL.length; i++) { |
|
25 |
var _srcNode = IriSP.jQuery('<source>'); |
|
26 |
_srcNode.attr({ |
|
27 |
src: videoURL[i].src, |
|
28 |
type: videoURL[i].type |
|
29 |
}); |
|
30 |
videoEl.append(_srcNode); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
jqselector.html(videoEl); |
|
35 |
|
|
36 |
var mediaEl = videoEl[0]; |
|
37 |
|
|
38 |
// Binding HTML video functions to media events |
|
39 |
media.on("setcurrenttime", function(_milliseconds) { |
|
40 |
try { |
|
41 |
mediaEl.currentTime = (_milliseconds / 1000); |
|
42 |
} catch (err) { |
|
43 |
|
|
44 |
} |
|
45 |
}); |
|
46 |
|
|
47 |
media.on("setvolume", function(_vol) { |
|
48 |
media.volume = _vol; |
|
49 |
try { |
|
50 |
mediaEl.volume = _vol; |
|
51 |
} catch (err) { |
|
52 |
|
|
53 |
} |
|
54 |
}); |
|
55 |
|
|
56 |
media.on("setmuted", function(_muted) { |
|
57 |
media.muted = _muted; |
|
58 |
try { |
|
59 |
mediaEl.muted = _muted; |
|
60 |
} catch (err) { |
|
61 |
|
|
62 |
} |
|
63 |
}); |
|
64 |
|
|
|
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
mediaEl.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
|
70 |
} |
|
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
|
71 |
} 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
|
72 |
} |
|
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
|
73 |
}) |
|
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
|
74 |
|
|
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
|
75 |
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
|
76 |
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
|
77 |
}) |
|
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
|
78 |
|
| 998 | 79 |
media.on("setplay", function() { |
80 |
try { |
|
81 |
mediaEl.play(); |
|
82 |
} catch (err) { |
|
83 |
|
|
84 |
} |
|
85 |
}); |
|
86 |
|
|
87 |
media.on("setpause", function() { |
|
88 |
try { |
|
89 |
mediaEl.pause(); |
|
90 |
} catch (err) { |
|
91 |
|
|
92 |
} |
|
93 |
}); |
|
94 |
|
|
95 |
// Binding DOM events to media |
|
96 |
function getVolume() { |
|
97 |
media.muted = mediaEl.muted; |
|
98 |
media.volume = mediaEl.volume; |
|
99 |
} |
|
100 |
|
|
101 |
videoEl.on("loadedmetadata", function() { |
|
102 |
getVolume(); |
|
103 |
media.trigger("loadedmetadata"); |
|
104 |
media.trigger("volumechange"); |
|
| 1013 | 105 |
}); |
| 998 | 106 |
|
107 |
videoEl.on("timeupdate", function() { |
|
108 |
media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime)); |
|
109 |
}); |
|
110 |
|
|
111 |
videoEl.on("volumechange", function() { |
|
112 |
getVolume(); |
|
113 |
media.trigger("volumechange"); |
|
| 1013 | 114 |
}); |
| 998 | 115 |
|
116 |
videoEl.on("play", function() { |
|
117 |
media.trigger("play"); |
|
118 |
}); |
|
119 |
|
|
120 |
videoEl.on("pause", function() { |
|
121 |
media.trigger("pause"); |
|
122 |
}); |
|
123 |
|
|
124 |
videoEl.on("seeking", function() { |
|
125 |
media.trigger("seeking"); |
|
126 |
}); |
|
127 |
|
|
128 |
videoEl.on("seeked", function() { |
|
129 |
media.trigger("seeked"); |
|
130 |
}); |
|
131 |
|
|
132 |
}; |