-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
158 lines (143 loc) · 4.81 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>epic-video-player demo</title>
<style>
#source-selector {
margin-bottom: 1rem;
}
#rendition-selector {
margin-top: 1rem;
}
#stats {
padding: 0.5rem;
border: 1px solid gray;
border-radius: 4px;
}
</style>
</head>
<body>
<h3 id="player-type"></h3>
<select id="source-selector"></select>
<video id="my-video" style="width: 100%" autoplay controls muted></video>
<select id="rendition-selector">
<option value="-1">Auto</option>
</select>
<button id="rendition-button">Change!</button>
<h4>Stats</h5>
<pre id="stats"></pre>
<script type="text/javascript">
let myPlayer = window.myPlayer;
const sources = [
{
src: 'https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd',
label: 'MPEG-DASH',
},
{
src: 'https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8',
label: 'HLS',
},
{
src: 'http://techslides.com/demos/sample-videos/small.mp4',
label: 'MP4',
},
{
src: 'https://dl6.webmfiles.org/elephants-dream.webm',
label: 'WebM',
},
{
src: 'https://archive.org/download/SampleVideo_908/Bear.ogv',
label: 'Ogg',
},
];
function initSourcesDemoFeatures() {
const select = document.getElementById('source-selector');
for (const source of sources) {
const option = document.createElement('option');
option.setAttribute('value', source.src);
option.text = source.label;
select.appendChild(option);
}
select.onchange = () => {
myPlayer.destroy();
const selectedValue = select.options[select.selectedIndex].value;
myPlayer = evp.newPlayer(
selectedValue,
document.getElementById('my-video'),
);
updatePlayerType();
};
}
function initRenditionsDemoFeatures() {
myPlayer.htmlPlayer.oncanplay = () => {
cleanRenditionsInSelector();
addRenditionsToSelector(myPlayer.getRenditions());
};
document
.getElementById('rendition-button')
.addEventListener('click', () => changeRendition());
}
function cleanRenditionsInSelector() {
const select = document.getElementById('rendition-selector');
while (select.children[1]) {
select.children[1].remove();
}
}
function addRenditionsToSelector(renditions) {
const select = document.getElementById('rendition-selector');
const button = document.getElementById('rendition-button');
if (!renditions.length) {
select.setAttribute('disabled', '');
button.setAttribute('disabled', '');
} else {
select.removeAttribute('disabled');
button.removeAttribute('disabled');
for (const rendition of renditions) {
const option = document.createElement('option');
option.setAttribute('value', JSON.stringify(rendition));
const dimensions = `${rendition.width}x${rendition.height}`;
const bitrate = `${Math.ceil(rendition.bitrate / 1000)} kbps`;
option.text = `${dimensions} - ${bitrate}`;
select.appendChild(option);
}
}
}
function changeRendition() {
const select = document.getElementById('rendition-selector');
const selectedRendition = select.options[select.selectedIndex].value;
if (selectedRendition === '-1') {
myPlayer.setRendition(-1, true);
} else {
myPlayer.setRendition(JSON.parse(selectedRendition), true);
}
}
function updatePlayerType() {
const placeholder = document.getElementById('player-type');
placeholder.innerText = `Using ${myPlayer.playerType} Player`;
}
function updateStats() {
const stats = document.getElementById('stats');
setInterval(() => {
if (myPlayer) {
stats.innerText = JSON.stringify(myPlayer.getStats(), null, 2);
} else {
stats.innerText = '';
}
}, 2_000);
}
document.addEventListener('DOMContentLoaded', () => {
myPlayer = evp.newPlayer(
sources[0].src,
document.getElementById('my-video'),
);
updateStats();
updatePlayerType();
initSourcesDemoFeatures();
initRenditionsDemoFeatures();
});
</script>
</body>
</html>