This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
epgsongs.js
51 lines (47 loc) · 1.7 KB
/
epgsongs.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
const playlist = [{
name: 'earlyMorning',
times: [0, 1, 2, 3, 4, 5, 6],
songs: ["https://node-05.zeno.fm/et8ras3bf2zuv?rj-ttl=5&rj-tok=AAABctPbN-gAdr8w383qCwBLqg"]
},
{
name: 'morning',
times: [6, 7, 8, 9],
songs: ["https://node-17.zeno.fm/7rgndyacf2zuv?rj-ttl=5&rj-tok=AAABctPZudgAze2xP4fRZyIKrA"]
},
{
name: 'primetime',
times: [19, 20],
songs: ["https://node-29.zeno.fm/yxauxfbcf2zuv?rj-ttl=5&rj-tok=AAABctPYKFoAi8K4mN5Rt6XcwA"]
},
{
name: 'daytime',
times: [11, 12, 13, 14, 15, 16, 17, 18],
songs: ["https://node-01.zeno.fm/bwens44bf2zuv?rj-ttl=5&rj-tok=AAABctPalBQAZFB71eI9Tm_EZw"]
},
{
name: 'nightclub',
times: [21, 22, 23],
songs: ["https://node-27.zeno.fm/vq7vtswbf2zuv?rj-ttl=5&rj-tok=AAABctOV6GQADgjz5v0t46Ro9w"]
}
]
let nowPlaying = null;
const player = document.getElementById("player"); // Get Audio Element
player.autoplay = true;
player.addEventListener("ended", function () {
player.currentTime = 0;
console.log(`${selection} ended`);
selectRandom();
});
function selectRandom() {
// destructure object because all we want is the song array
const { songs } = playlist.find(list => list.times.includes(new Date().getHours()));
// remove the currently playing song, or nothing if null
const filteredSongs = songs.filter(song => song != nowPlaying);
// pick a random song out of the remaining songs
const selection = filteredSongs[Math.floor(Math.random() * filteredSongs.length)]
lastSong = selection; // Remember last song
player.src = selection; // Tell HTML the location of the new Song
console.log(`Now playing ${selection}`);
}
selectRandom(); // Select initial song
player.play; // Start song