-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
172 lines (150 loc) · 4.43 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Radio stations
var stations = [
{
"title": "Ретро Хит",
"stream": "http://air.volna.top/Retro"
},
{
"title": "Европа Плюс",
"stream": "http://78.111.244.206/euro32.mp3"
},
{
"title": "NonStopPlay",
"stream": "http://stream.nonstopplay.co.uk/nsp-128k-mp3"
},
{
"title": "Radio Record",
"stream": "http://air.radiorecord.ru:8101/rr_320"
},
{
"title": "Jazz FM Legends",
"stream": "http://jazz128legends.streamr.ru/"
},
{
"title": "Trancemission",
"stream": "http://air.radiorecord.ru:8102/tm_320"
},
{
"title": "Дискотека 90-ых",
"stream": "http://air.radiorecord.ru:8102/sd90_320 "
},
{
"title": "Joy Radio",
"stream": "http://airtime.joyradio.cc:8000/airtime_192.mp3"
},
{
"title": "Fip Radio",
"stream": "http://direct.fipradio.fr/live/fip-midfi.mp3"
},
{
"title": "Dubstep",
"stream": "http://air.radiorecord.ru:8102/dub_320"
},
{
"title": "Страна FM",
"stream": "http://icecast.stranafm.cdnvideo.ru/stranafm_128"
},
{
"title": "Music Radio",
"stream": "http://ice-the.musicradio.com/CapitalXTRANationalMP3"
},
{
"title": "Classical Music",
"stream": "http://stream.srg-ssr.ch/m/rsc_de/mp3_128"
},
{
"title": "Live Icy",
"stream": "http://live-icy.gss.dr.dk:8000/A/A05H.mp3"
},
{
"title": "Старое Радио",
"stream": "http://195.91.237.50:8000/music32"
}
];
var backgrounds = [
'images/1.jpg',
'images/2.jpg',
'images/3.jpg',
'images/4.jpg',
'images/5.jpg',
'images/6.jpg',
'images/7.jpg',
'images/8.jpg',
'images/9.jpg',
'images/10.jpg',
'images/11.jpg',
'images/12.jpg',
'images/13.jpg',
'images/14.jpg'
];
var app = {
init: function () {
// DOM elements
this.$player = $('audio');
this.$playControl = $('.play-control');
this.$background = $('.background');
this.$backgroundOverlay = $('.background-overlay');
// Variables
this.rotationInterval = 30000;
// Functions
this.registerPlayerHandlers();
this.loadStations();
this.initBackgroundChanger();
},
registerPlayerHandlers: function () {
this.$playControl.on('click', function () {
app.$playControl.removeClass('fa-pause fa-play');
// Toggle play status
if (app.$player[0].paused === true) {
// Play the station
app.$playControl.addClass('fa-play');
app.$player[0].play();
} else {
// Pause the station
app.$playControl.addClass('fa-pause');
app.$player[0].pause();
}
});
},
loadStations: function () {
$(stations).each(function(index, station) {
// Set default favicon
station.favicon = 'images/galaxy.png';
// Append to station list
var element = '<div id="station-' + index + '" class="station"><div class="station-icon" style="background-image: url(' + station.favicon + ');"></div><div class="station-title">' + station.title + '</div>';
$('.container.stations').append(element);
});
// Load audio
$('.station').on('click', function () {
var $station = $(this);
var stationId = $station.attr('id').replace('station-', '');
var stationUrl = stations[stationId].stream;
// Show selected station
$station.addClass('station-selected');
$station.siblings().removeClass('station-selected');
// Add station url to audio player
app.$player.attr('src', stationUrl);
app.$playControl.removeClass('fa-pause').addClass('fa-play');
});
},
initBackgroundChanger: function () {
// Set the default backgrounds
var index = Math.floor(Math.random() * backgrounds.length);
app.$background.css('backgroundImage', 'url(' + backgrounds[index] + ')');
app.$backgroundOverlay.css('backgroundImage', 'url(' + backgrounds[index] + ')');
// Update the background image
setInterval(function () {
// Select a random background
var index = Math.floor(Math.random() * backgrounds.length);
app.$background.css('backgroundImage', 'url(' + backgrounds[index] + ')');
// Transition the image
app.$backgroundOverlay.fadeOut(5000, function () {
app.$backgroundOverlay.css('backgroundImage', 'url(' + backgrounds[index] + ')');
app.$backgroundOverlay.fadeIn(5000);
});
}, this.rotationInterval);
}
};
$(window).load(function () {
app.init();
})