This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.html
228 lines (193 loc) · 6.22 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!doctype html>
<html>
<head>
<title><hls-video></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
<style>
body {
text-align: center;
}
media-controller {
display: block;
aspect-ratio: 16 / 9;
background: transparent;
}
hls-video[slot] {
/* Fix Safari aspect-ratio overflow glitch */
height: fit-content;
}
hls-video:not([slot]) {
aspect-ratio: 16 / 9;
width: 100%;
}
nav {
display: flex;
justify-content: space-between;
}
</style>
<script async src="https://cdn.jsdelivr.net/npm/es-module-shims"></script>
<script type="importmap">
{
"imports": {
"custom-media-element": "https://cdn.jsdelivr.net/npm/[email protected]/+esm",
"media-tracks": "https://cdn.jsdelivr.net/npm/[email protected]/+esm",
"hls.js/": "https://cdn.jsdelivr.net/npm/[email protected]/"
}
}
</script>
<script type="module" src="https://cdn.jsdelivr.net/npm/media-chrome/+esm"></script>
</head>
<body>
<h1><hls-video></h1>
<br>
<h2>On-demand</h2>
<hls-video
id="myVideo"
controls
src="https://stream.mux.com/Sc89iWAyNkhJ3P1rQ02nrEdCFTnfT01CZ2KmaEcxXfB008.m3u8"
poster="https://image.mux.com/Sc89iWAyNkhJ3P1rQ02nrEdCFTnfT01CZ2KmaEcxXfB008/thumbnail.webp"
crossorigin
playsinline
></hls-video>
<br>
<nav>
<nav>
<button id="loadbtn">Load new clip</button>
<button id="removebtn">Remove first rendition</button>
</nav>
<nav>
<select id="audioselect"></select>
<select id="qualityselect">
<option value="auto">Auto</option>
</select>
<input id="qualityselected" value="N/A" readonly size="5">
</nav>
</nav>
<script type="module">
import './hls-video-element.js';
myVideo.audioTracks.addEventListener('removetrack', ({ track }) => {
audioselect.querySelector(`[value="${track.id}"]`).remove();
});
myVideo.audioTracks.addEventListener('addtrack', ({ track }) => {
audioselect.append(new Option(
track.label,
track.id,
track.enabled,
track.enabled
));
});
audioselect.addEventListener('change', () => {
for (let track of myVideo.audioTracks) {
track.enabled = audioselect.value == track.id;
}
});
myVideo.videoTracks.addEventListener('removetrack', ({ track }) => {
let i = qualityselect.options.length;
while (--i) qualityselect.options.remove(i);
});
myVideo.videoRenditions.addEventListener('addrendition', ({ rendition }) => {
qualityselect.append(new Option(
`${Math.min(rendition.width, rendition.height)}p`,
rendition.id,
));
});
myVideo.videoRenditions.addEventListener('removerendition', ({ rendition }) => {
qualityselect.querySelector(`[value="${rendition.id}"]`).remove();
});
myVideo.addEventListener('resize', () => {
qualityselected.value = `${Math.min(myVideo.videoWidth, myVideo.videoHeight)}p`;
});
loadbtn.onclick = () => {
myVideo.src = 'https://stream.mux.com/1EFcsL5JET00t00mBv01t00xt00T4QeNQtsXx2cKY6DLd7RM.m3u8';
};
removebtn.onclick = () => {
myVideo.api.removeLevel(0);
};
qualityselect.addEventListener('change', () => {
myVideo.videoRenditions.selectedIndex = qualityselect.selectedIndex - 1;
});
</script>
<h2>Live</h2>
<hls-video
controls
src="https://stream.mux.com/v69RSHhFelSm4701snP22dYz2jICy4E4FUyk02rW4gxRM"
crossorigin
playsinline
></hls-video>
<script>
const video = document.querySelector('hls-video');
video.addEventListener('emptied', (e) => {
console.log(e.type);
});
video.addEventListener('loadstart', (e) => {
console.log(e.type);
});
video.addEventListener('loadedmetadata', (e) => {
console.log(e.type);
});
video.addEventListener('loadeddata', (e) => {
console.log(e.type);
});
video.addEventListener('play', (e) => {
console.log(e.type);
});
video.addEventListener('waiting', (e) => {
console.log(e.type);
});
video.addEventListener('playing', (e) => {
console.log(e.type);
});
video.addEventListener('pause', (e) => {
console.log(e.type);
});
video.addEventListener('seeking', (e) => {
console.log(e.type);
});
video.addEventListener('seeked', (e) => {
console.log(e.type);
});
video.addEventListener('ended', (e) => {
console.log(e.type);
});
video.addEventListener('durationchange', (e) => {
console.log(e.type, video.duration);
});
video.addEventListener('volumechange', (e) => {
console.log(e.type, video.volume);
});
video.addEventListener('resize', (e) => {
console.log(e.type, video.videoWidth, video.videoHeight);
});
</script>
<br>
<h2>With <a href="https://github.com/muxinc/media-chrome" target="_blank">Media Chrome</a></h2>
<media-controller>
<hls-video
src="https://stream.mux.com/O6LdRc0112FEJXH00bGsN9Q31yu5EIVHTgjTKRkKtEq1k.m3u8"
poster="https://image.mux.com/O6LdRc0112FEJXH00bGsN9Q31yu5EIVHTgjTKRkKtEq1k/thumbnail.jpg?time=56"
crossorigin
playsinline
slot="media"
muted
>
<track default kind="metadata" label="thumbnails" src="https://image.mux.com/O6LdRc0112FEJXH00bGsN9Q31yu5EIVHTgjTKRkKtEq1k/storyboard.vtt">
</hls-video>
<media-loading-indicator slot="centered-chrome" no-auto-hide></media-loading-indicator>
<media-control-bar>
<media-play-button></media-play-button>
<media-seek-backward-button seek-offset="15"></media-seek-backward-button>
<media-seek-forward-button seek-offset="15"></media-seek-forward-button>
<media-mute-button></media-mute-button>
<media-volume-range></media-volume-range>
<media-time-range></media-time-range>
<media-time-display show-duration remaining></media-time-display>
<media-playback-rate-button></media-playback-rate-button>
<media-pip-button></media-pip-button>
<media-fullscreen-button></media-fullscreen-button>
</media-control-bar>
</media-controller>
<br>
<br>
</body>
</html>