-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (69 loc) · 1.79 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const playpauseBtn = document.getElementById("playpauseBtn");
const nextBtn = document.getElementById("nextBtn");
const previousBtn = document.getElementById("previousBtn");
const frame = document.getElementById("frame");
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '400',
width: '400',
playerVars: {
'playsinline': 1,
'controls': 0,
'disablekb': 1,
'modestbranding': 1,
'rel': 0,
'loop': 1,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
player.loadPlaylist({
list: 'PLfLLIpJ53SP_JQuviwlZgTqVttaLHPU-7',
listType: 'playlist',
})
event.target.stopVideo();
}
var playing;
function onPlayerStateChange(event) {
playing = event.data == YT.PlayerState.PLAYING ? true : false;
}
function pauseVideo() {
player.pauseVideo();
}
function playVideo() {
player.seekTo(player.getDuration())
player.playVideo();
}
function nextVideo() {
player.nextVideo();
}
function previousVideo() {
player.previousVideo();
}
function Init() {
frame.style.height = frame.clientWidth;
}
window.onload = Init();
playpauseBtn.onclick = () => {
if (playing) {
pauseVideo();
}
else {
playVideo();
}
}
nextBtn.onclick = () => {
nextVideo();
}
previousBtn.onclick = () => {
previousVideo();
}