forked from gliese1337/HLS.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.js
53 lines (44 loc) · 1.62 KB
/
browser.js
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
'use strict';
var player = null,
canvas = document.getElementById('canvas'),
playbtn = document.getElementById('play'),
seeker = document.getElementById('seeker'),
rate = document.getElementById('rate'),
volume = document.getElementById('volume'),
manifest = document.getElementById('manifest');
function playpause(){
player[(player.paused)?'play':'pause']();
}
function init(){
player = new HLSPlayer(canvas, manifest.value);
playbtn.removeEventListener('click', init, false);
player.addEventListener('ready', function(){
playbtn.textContent = "Play";
playbtn.addEventListener('click', playpause, false);
seeker.max = player.duration;
seeker.addEventListener('change', function(){
player.currentTime = seeker.value;
}, false);
rate.addEventListener('change', function(){
player.playbackRate = rate.value;
}, false);
volume.addEventListener('change', function(){
player.volume = volume.value;
}, false);
}, false);
player.addEventListener('timeupdate',function(){
seeker.value = player.currentTime;
}, false);
player.addEventListener('play', function(){ playbtn.textContent = "Pause"; }, false);
player.addEventListener('pause', function(){ playbtn.textContent = "Play"; }, false);
player.addEventListener('ended', function(){
playbtn.textContent = "Play";
player.currentTime = 0;
}, false);
}
playbtn.addEventListener('click', init, false);
})();