-
Notifications
You must be signed in to change notification settings - Fork 4
/
player.js
66 lines (58 loc) · 1.65 KB
/
player.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
54
55
56
57
58
59
60
61
62
63
64
65
66
var video = document.getElementById('video');
function playM3u8(url){
if(Hls.isSupported()) {
video.volume = 0.3;
var hls = new Hls();
var m3u8Url = decodeURIComponent(url)
hls.loadSource(m3u8Url);
hls.attachMedia(video);
hls.subtitleDisplay = false; //disable subtitles
hls.subtitleTrack = 0; //disable subtitles
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
document.title = url
}
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
video.addEventListener('canplay',function() {
video.play();
});
video.volume = 0.3;
document.title = url;
}
}
function playPause() {
video.paused?video.play():video.pause();
}
function volumeUp() {
if(video.volume <= 0.9) video.volume+=0.1;
}
function volumeDown() {
if(video.volume >= 0.1) video.volume-=0.1;
}
function seekRight() {
video.currentTime+=5;
}
function seekLeft() {
video.currentTime-=5;
}
function vidFullscreen() {
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen();
}
}
playM3u8(window.location.href.split("#")[1])
$(window).on('load', function () {
$('#video').on('click', function(){this.paused?this.play():this.pause();});
Mousetrap.bind('space', playPause);
Mousetrap.bind('up', volumeUp);
Mousetrap.bind('down', volumeDown);
Mousetrap.bind('right', seekRight);
Mousetrap.bind('left', seekLeft);
Mousetrap.bind('f', vidFullscreen);
});