|
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, |
|
16 height : opts.height || undefined |
|
17 }); |
|
18 |
|
19 if(typeof videoURL === "string"){ |
|
20 videoEl.attr("src",videoURL); |
|
21 } else { |
|
22 for (var i = 0; i < videoURL.length; i++) { |
|
23 var _srcNode = IriSP.jQuery('<source>'); |
|
24 _srcNode.attr({ |
|
25 src: videoURL[i].src, |
|
26 type: videoURL[i].type |
|
27 }); |
|
28 videoEl.append(_srcNode); |
|
29 } |
|
30 } |
|
31 |
|
32 jqselector.html(videoEl); |
|
33 |
|
34 if (opts.autostart || opts.autoplay) { |
|
35 videoEl.attr("autoplay", true); |
|
36 } |
|
37 |
|
38 var mediaEl = videoEl[0]; |
|
39 |
|
40 // Binding HTML video functions to media events |
|
41 media.on("setcurrenttime", function(_milliseconds) { |
|
42 try { |
|
43 mediaEl.currentTime = (_milliseconds / 1000); |
|
44 } catch (err) { |
|
45 |
|
46 } |
|
47 }); |
|
48 |
|
49 media.on("setvolume", function(_vol) { |
|
50 media.volume = _vol; |
|
51 try { |
|
52 mediaEl.volume = _vol; |
|
53 } catch (err) { |
|
54 |
|
55 } |
|
56 }); |
|
57 |
|
58 media.on("setmuted", function(_muted) { |
|
59 media.muted = _muted; |
|
60 try { |
|
61 mediaEl.muted = _muted; |
|
62 } catch (err) { |
|
63 |
|
64 } |
|
65 }); |
|
66 |
|
67 media.on("setplay", function() { |
|
68 try { |
|
69 mediaEl.play(); |
|
70 } catch (err) { |
|
71 |
|
72 } |
|
73 }); |
|
74 |
|
75 media.on("setpause", function() { |
|
76 try { |
|
77 mediaEl.pause(); |
|
78 } catch (err) { |
|
79 |
|
80 } |
|
81 }); |
|
82 |
|
83 // Binding DOM events to media |
|
84 function getVolume() { |
|
85 media.muted = mediaEl.muted; |
|
86 media.volume = mediaEl.volume; |
|
87 } |
|
88 |
|
89 videoEl.on("loadedmetadata", function() { |
|
90 getVolume(); |
|
91 media.trigger("loadedmetadata"); |
|
92 media.trigger("volumechange"); |
|
93 }) |
|
94 |
|
95 videoEl.on("timeupdate", function() { |
|
96 media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime)); |
|
97 }); |
|
98 |
|
99 videoEl.on("volumechange", function() { |
|
100 getVolume(); |
|
101 media.trigger("volumechange"); |
|
102 }) |
|
103 |
|
104 videoEl.on("play", function() { |
|
105 media.trigger("play"); |
|
106 }); |
|
107 |
|
108 videoEl.on("pause", function() { |
|
109 media.trigger("pause"); |
|
110 }); |
|
111 |
|
112 videoEl.on("seeking", function() { |
|
113 media.trigger("seeking"); |
|
114 }); |
|
115 |
|
116 videoEl.on("seeked", function() { |
|
117 media.trigger("seeked"); |
|
118 }); |
|
119 |
|
120 |
|
121 }; |