-
Notifications
You must be signed in to change notification settings - Fork 13
/
playback.js
67 lines (57 loc) · 1.77 KB
/
playback.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
const sources = [
"http://stream-dc1.radioparadise.com/aac-320", // paradise
"http://radiogong-ais-edge-3073-fra-eco-cdn.cast.addradio.de/radiogong/live/mp3/high?ar-distributor=f0b7&aw_0_req.gdpr=true&_art=dj0yJmlwPTYyLjU3LjIuMjcmaWQ9aWNzY3hsLXMzeGRnenhtYiZ0PTE2MTAzODM3MDcmcz03ODY2ZjI5YyNiNzcwYWViOGUxZWU0NWI2MWJlNTAzZWE4OWUyZjQwYw", // party gong
"http://ice2.somafm.com/folkfwd-128-mp3", // folk forward
"http://94.23.26.22:8090/live.mp3" // punk fm
];
const labels = [
[ "Radio Paradise", "https://www.radioparadise.com" ],
[ "Party Gong", "https://www.radiogong.de/"],
[ "SomaFM Folk Forward", "http://somafm.com/folkfwd/"],
[ "Punk FM", " http://www.punkfm.co.uk/"]
];
let playingIndex = 0; // current radio
let playing = true; // stream status
let music = null;
setTimeout(function(){
loadStream(playingIndex);
}, 1);
function loadStream(index){
if(playing && music !== null)
destroyStream();
music = new Audio();
music.src = sources[index];
music.load();
music.play();
setLabel(index);
pauseIcon();
playingIndex = index;
playing = true;
}
function destroyStream(){
music.pause();
music.src = "";
playIcon();
playing = false;
}
function changePlayback(){
if(playing){ destroyStream(); }else{ loadStream(playingIndex); }
}
function setLabel(index){
document.getElementById("label").innerHTML = '<h6> <a target="_blank" href="' + labels[index][1] + '">' + labels[index][0] + '</a></h6>';
}
document.onkeydown = function(e) {
e = e || window.event;
switch(e.which || e.keyCode) {
case 32:
changePlayback();
break;
}
};
// icons
function pauseIcon(){
document.getElementById('playbackButton').className = 'icon fa-pause';
}
function playIcon(){
document.getElementById('playbackButton').className = 'icon fa-play';
}