| author | ymh <ymh.work@gmail.com> |
| Fri, 18 Oct 2024 10:24:57 +0200 | |
| changeset 1074 | 231ea5ea7de4 |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
| 998 | 1 |
/* HTML player, to be reused in a widget, or elsewhere */ |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
2 |
import jQuery from "jquery"; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
3 |
const htmlPlayer = function(media, jqselector, options) { |
| 998 | 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 |
|
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
12 |
var videoEl = jQuery('<video>'); |
| 998 | 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++) { |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
25 |
var _srcNode = jQuery('<source>'); |
| 998 | 26 |
_srcNode.attr({ |
27 |
src: videoURL[i].src, |
|
28 |
type: videoURL[i].type |
|
29 |
}); |
|
30 |
videoEl.append(_srcNode); |
|
31 |
} |
|
32 |
} |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
33 |
if (opts.subtitle) { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
34 |
var _trackNode = jQuery('<track>'); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
35 |
_trackNode.attr({ |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
36 |
label: "Subtitles", |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
37 |
kind: "subtitles", |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
38 |
srclang: "fr", |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
39 |
src: opts.subtitle, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
40 |
default: "" |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
41 |
}); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
42 |
videoEl.append(_trackNode); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
43 |
} |
| 998 | 44 |
jqselector.html(videoEl); |
45 |
|
|
46 |
var mediaEl = videoEl[0]; |
|
47 |
|
|
48 |
// Binding HTML video functions to media events |
|
49 |
media.on("setcurrenttime", function(_milliseconds) { |
|
50 |
try { |
|
51 |
mediaEl.currentTime = (_milliseconds / 1000); |
|
52 |
} catch (err) { |
|
53 |
|
|
54 |
} |
|
55 |
}); |
|
56 |
|
|
57 |
media.on("setvolume", function(_vol) { |
|
58 |
media.volume = _vol; |
|
59 |
try { |
|
60 |
mediaEl.volume = _vol; |
|
61 |
} catch (err) { |
|
62 |
|
|
63 |
} |
|
64 |
}); |
|
65 |
|
|
66 |
media.on("setmuted", function(_muted) { |
|
67 |
media.muted = _muted; |
|
68 |
try { |
|
69 |
mediaEl.muted = _muted; |
|
70 |
} catch (err) { |
|
71 |
|
|
72 |
} |
|
73 |
}); |
|
74 |
|
|
|
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
} |
|
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
|
81 |
} 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
|
82 |
} |
|
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
|
83 |
}) |
|
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
|
84 |
|
|
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
|
85 |
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
|
86 |
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
|
87 |
}) |
|
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
|
88 |
|
| 998 | 89 |
media.on("setplay", function() { |
90 |
try { |
|
91 |
mediaEl.play(); |
|
92 |
} catch (err) { |
|
93 |
|
|
94 |
} |
|
95 |
}); |
|
96 |
|
|
97 |
media.on("setpause", function() { |
|
98 |
try { |
|
99 |
mediaEl.pause(); |
|
100 |
} catch (err) { |
|
101 |
|
|
102 |
} |
|
103 |
}); |
|
104 |
|
|
105 |
// Binding DOM events to media |
|
106 |
function getVolume() { |
|
107 |
media.muted = mediaEl.muted; |
|
108 |
media.volume = mediaEl.volume; |
|
109 |
} |
|
110 |
|
|
111 |
videoEl.on("loadedmetadata", function() { |
|
112 |
getVolume(); |
|
113 |
media.trigger("loadedmetadata"); |
|
114 |
media.trigger("volumechange"); |
|
| 1013 | 115 |
}); |
| 998 | 116 |
|
117 |
videoEl.on("timeupdate", function() { |
|
118 |
media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime)); |
|
119 |
}); |
|
120 |
|
|
121 |
videoEl.on("volumechange", function() { |
|
122 |
getVolume(); |
|
123 |
media.trigger("volumechange"); |
|
| 1013 | 124 |
}); |
| 998 | 125 |
|
126 |
videoEl.on("play", function() { |
|
127 |
media.trigger("play"); |
|
128 |
}); |
|
129 |
|
|
130 |
videoEl.on("pause", function() { |
|
131 |
media.trigger("pause"); |
|
132 |
}); |
|
133 |
|
|
134 |
videoEl.on("seeking", function() { |
|
135 |
media.trigger("seeking"); |
|
136 |
}); |
|
137 |
|
|
138 |
videoEl.on("seeked", function() { |
|
139 |
media.trigger("seeked"); |
|
140 |
}); |
|
141 |
|
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
142 |
videoEl.on("click", function() { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
143 |
if (mediaEl.paused) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
144 |
media.play(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
145 |
} else { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
146 |
media.pause(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
147 |
}; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
148 |
}); |
| 998 | 149 |
}; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
150 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
151 |
export default htmlPlayer; |