-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
82 lines (72 loc) · 2.05 KB
/
script.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
"use strict";
const videos = [
{
"name": "The Nights",
"url": "https://www.youtube.com/embed/UtF6Jej8yb4",
"srcId": "UtF6Jej8yb4"
},
{
"name": "Wake me Up",
"url": "https://www.youtube.com/embed/IcrbM1l_BoI",
"srcId": "IcrbM1l_BoI"
},
{
"name": "Waiting For Love",
"url": "https://www.youtube.com/embed/cHHLHGNpCSA",
"srcId": "cHHLHGNpCSA"
},
{
"name": "Without You",
"url": "https://www.youtube.com/embed/WRz2MxhAdJo",
"srcId": "WRz2MxhAdJo"
},
{
"name": "Hey Brother",
"url": "https://www.youtube.com/embed/6Cp6mKbRTQY",
"srcId": "6Cp6mKbRTQY"
},
{
"name": "Levels",
"url": "https://www.youtube.com/embed/_ovdm2yX4MA",
"srcId": "_ovdm2yX4MA"
}
]
// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
const songName = document.getElementById('song-name');
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('youtubePlayer', {
videoId: 'UtF6Jej8yb4'
});
songName.innerHTML = videos[0].name;
}
var icurrent = 0;
var inext = 1;
var iprev = videos.length - 1;
var listLenght = videos.length;
function setVideo(iv){
songName.innerHTML = videos[iv].name;
console.log(videos[iv].srcId);
player.loadVideoById(videos[iv].srcId);
}
document.getElementById('next').addEventListener('click', ()=>{
icurrent = inext;
setVideo(icurrent);
inext++;
inext > listLenght - 1 ? inext = 0 : inext;
iprev++;
iprev > listLenght - 1 ? iprev = 0 : iprev;
});
document.getElementById('prev').addEventListener('click', ()=>{
icurrent = iprev;
setVideo(icurrent);
iprev--;
iprev < 0 ? iprev = listLenght - 1 : iprev;
inext--;
inext < 0 ? inext = listLenght - 1 : inext;
});
// --> End Video Player