-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.js
More file actions
76 lines (62 loc) · 1.49 KB
/
loading.js
File metadata and controls
76 lines (62 loc) · 1.49 KB
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
//Array randomizer
function randOrd(){
return (Math.round(Math.random())-0.5); }
function setMusicName(name) {
$("#music-name").fadeOut(2000, function() {
$(this).html(name);
$(this).fadeIn(2000);
});
}
var youtubePlayer;
var actualMusic = -1;
$(function() {
l_musicPlaylist = l_musicPlaylist.sort( randOrd );
if (l_music) {
loadYoutube();
$("#music").fadeIn(2000);
}
});
function loadYoutube() {
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
youtubePlayer = new YT.Player('player', {
height: '0',
width: '0',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
youtubePlayer.setVolume(l_musicVolume);
nextMusic();
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
nextMusic();
}
}
function nextMusic() {
actualMusic++;
if (actualMusic >= l_musicPlaylist.length) {
actualMusic = 0;
}
var atual = l_musicPlaylist[actualMusic];
console.log(atual);
if (atual.youtube) {
youtubePlayer.loadVideoById(atual.youtube);
}else{
$("body").append('<audio src="'+atual.ogg+'" autoplay>');
$("audio").prop('volume', l_musicVolume/100);
$("audio").bind("ended", function() {
$(this).remove();
nextMusic();
});
}
setMusicName(atual.name);
}