-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
75 lines (64 loc) · 2.03 KB
/
Copy pathindex.html
File metadata and controls
75 lines (64 loc) · 2.03 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video HLS Adaptive streaming</title>
<link href="//vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
<script src="//vjs.zencdn.net/7.10.2/video.min.js"></script>
</head>
<body>
<video
id="my_video_1"
class="video-js vjs-default-skin"
type="application/x-mpegURL"
src="./output/master.m3u8"
width="640"
height="268"
controls>
</video>
<script src="https://vjs.zencdn.net/8.3.0/video.min.js"></script>
<script>
const video = document.querySelector('#my_video_1')
const src = video.getAttribute('src')
const type = video.getAttribute('type')
const player = videojs(video)
player.src({
src: src,
type: type
})
let qualityLevels = player.qualityLevels();
// disable quality levels with less than 720 horizontal lines of resolution when added
// to the list.
qualityLevels.on('addqualitylevel', function(event) {
let qualityLevel = event.qualityLevel;
if (qualityLevel.height >= 720) {
qualityLevel.enabled = true;
} else {
qualityLevel.enabled = false;
}
});
// example function that will toggle quality levels between SD and HD, defining and HD
// quality as having 720 horizontal lines of resolution or more
let toggleQuality = (function() {
let enable720 = true;
return function() {
for (let qualityLevel of qualityLevels) {
if (qualityLevel.height >= 720) {
qualityLevel.enabled = enable720;
} else {
qualityLevel.enabled = !enable720;
}
}
enable720 = !enable720;
};
})();
let currentSelectedQualityLevelIndex = qualityLevels.selectedIndex; // -1 if no level selected
// Listen to change events for when the player selects a new quality level
qualityLevels.on('change', function() {
console.log('Quality Level changed!');
console.log('New level:', qualityLevels[qualityLevels.selectedIndex]);
});
</script>
</body>
</html>