-
Notifications
You must be signed in to change notification settings - Fork 1
/
youtube.js
48 lines (42 loc) · 1.18 KB
/
youtube.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
(function(Remotes){
var player = document.getElementById('movie_player');
var NEXT = 1,
PREVIOUS = -1,
PLAYING = 1,
PAUSED = 2;
function changeVideo(direction) {
if (player.getPlaylist && player.getPlaylist()) {
direction == NEXT ? player.nextVideo() : player.previousVideo();
return;
} else {
if (direction == NEXT) {
var related_videos = document.getElementsByClassName("related-video");
document.location = related_videos[0].href;
} else {
history.back();
return;
}
}
}
function togglePlayback() {
if (player.getPlayerState() == PLAYING) {
player.pauseVideo();
} else if (player.getPlayerState() == PAUSED) {
player.playVideo();
}
}
function setVolume(increment) {
player.setVolume(player.getVolume() + increment);
}
function toggleMute() {
player.isMuted() ? player.unMute() : player.mute();
}
Remotes
.on("swipe-left", function(e) { changeVideo(NEXT); })
.on("swipe-right", function(e) { changeVideo(PREVIOUS); })
.on("swipe-up", function(e) { setVolume(20); })
.on("swipe-down", function(e) { setVolume(-20); })
.on("tap", togglePlayback)
.on("hold", toggleMute)
.on("release", function(e){ });
})(new Remotes("preview"));