This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
65 lines (58 loc) · 1.65 KB
/
index.htm
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
<html>
<head>
<title>muse-room</title>
</head>
<!--
D6Ac5JpCHmI - share
-->
<body>
<!-- <iframe width="560" height="315" src="
https://www.youtube.com/embed/0HQqXllXpfQ?&autoplay=1" frameborder="0"
allowfullscreen>
</iframe> -->
<div id="ytplayer"></div>
<script>
var currentSong = 0;
var songIds = ["-fKLy0uKL3Y", "6bfTTeZOrs4"];
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Replace the 'ytplayer' element with an <iframe> and
// YouTube player after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '360',
width: '640',
videoId: songIds[currentSong],
playerVars: { 'autoplay': 1, 'controls': 1 },
events: {
'onReady':onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
shuffle(songIds);
currentSong++;
if(currentSong >= songIds.length){
currentSong = 0;
}
player.loadVideoById(songIds[currentSong]);
}
}
function onPlayerReady(event){
event.target.playVideo();
}
function shuffle(a) {
for (let i = a.length; i; i--) {
let j = Math.floor(Math.random() * i);
[a[i - 1], a[j]] = [a[j], a[i - 1]];
}
}
</script>
</body>
</html>