-
Notifications
You must be signed in to change notification settings - Fork 13
/
playlist-mini.php
350 lines (293 loc) · 12.4 KB
/
playlist-mini.php
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
// +------------------------------------------------------------------------+
// | O!MPD, Copyright © 2015-2019 Artur Sierzant |
// | http://www.ompd.pl |
// | |
// | |
// | netjukebox, Copyright © 2001-2012 Willem Bartels |
// | |
// | http://www.netjukebox.nl |
// | http://forum.netjukebox.nl |
// | |
// | This program is free software: you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation, either version 3 of the License, or |
// | (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program. If not, see <http://www.gnu.org/licenses/>. |
// +------------------------------------------------------------------------+
// +------------------------------------------------------------------------+
// | playlist-mini.php |
// +------------------------------------------------------------------------+
require_once('include/play.inc.php');
?>
<!-- info + control -->
<div id="info_area_mini">
<div id="timebar_mini"></div>
<div id="image_container_mini" title="Go to Now Playing">
<!-- <div id="image_mini"> -->
<a href="playlist.php"><img id="image_in_mini" src="image/transparent.gif" alt=""></a>
<!-- </div> -->
</div>
<div id="file-info-mini">
<span id="track_number"> </span><span class="track_title_mini" id="track_title_mini"> </span>
<div class="artist_mini" id="artist_mini"> </div>
</div>
<!-- <div class="pl-track-info-rightMini"> -->
<!-- begin controll bar -->
<div id="media_control_mini">
<div class="control-rowMini">
<div class="playlist_button"><div class="playlist_status_off" name="previous" id="previous" onclick="javascript:ajaxRequest('play.php?action=prev&menu=playlist');">
<i class="fa fa-fast-backward sign-ctrl"></i>
</div></div>
<div class="playlist_button"><div class="playlist_status_off" name="play" id="play" onclick="javascript:ajaxRequest('play.php?action=play&menu=playlist', evaluateIsplaying);">
<i class="fa fa-play sign-ctrl"></i>
</div></div>
<div class="playlist_button" style="display: none;"><div class="playlist_status_off" name="stop" id="stop" onclick="javascript:ajaxRequest('play.php?action=stop&menu=playlist', evaluateIsplaying);">
<i class="fa fa-stop sig"></i>
</div></div>
<div class="playlist_button" style=""><div class="playlist_status_off" name="next" id="next" onclick="javascript:ajaxRequest('play.php?action=next&menu=playlist', evaluateIsplaying);">
<i class="fa fa-fast-forward sign-ctrl"></i>
</div></div>
</div>
</div>
<!-- </div> -->
<!-- end controll bar -->
</div>
<!-- end info + controll -->
<script type="text/javascript">
<!--
var previous_hash = '';
var previous_listpos = '';
var previous_isplaying = -1; // force update
var previous_repeat = -1;
var previous_shuffle = -1;
var previous_gain = -1;
var previous_miliseconds = -1;
var previous_track_id = 'ff';
var track_id = '';
var current_track_id = '';
var timer_id = 0;
var timer_function = 'ajaxRequest("play.php?action=playlistStatus&menu=playlist", evaluateStatus)';
var timer_delay = 1000;
var list_length = '';
var fromPosition = -1
var testing = '<?php echo $cfg['testing']; ?>';
getTrackIDs();
ajaxRequest('play.php?action=playlistTrack&track_id=' + track_id[previous_listpos] + '&menu=playlist', evaluateTrack);
ajaxRequest('play.php?action=playlistStatus&track_id=' + track_id[previous_listpos] + '&menu=playlist', evaluateStatus);
function getTrackIDs() {
$.ajax({
url: 'ajax-playlist-mini.php',
type: 'GET',
async: false,
dataType : 'json',
error: function(){
return true;
},
success: function(json){
evaluateTrackIDs(json);
}
});
}
function evaluateTrackIDs(data) {
track_id = data.track_id;
previous_hash = data.hash;
previous_listpos = data.listpos;
list_length = data.listlength;
}
function evaluateStatus(data) {
// data.hash, data.miliseconds, data.listpos, data.volume
// data.isplaying, data.repeat, data.shuffle, data.gain
if (previous_hash != data.hash) {
getTrackIDs();
ajaxRequest('play.php?action=playlistTrack&track_id=' + track_id[previous_listpos] + '&menu=playlist', evaluateTrack);
}
if (data.totalTracks > 0) {
document.getElementById('track_number').innerHTML = (data.listpos + 1) + "/" + data.totalTracks + ". ";
}
else {
document.getElementById('track_number').innerHTML = "Playlist is empty";
document.getElementById('artist_mini').innerHTML = "";
}
evaluateListpos(data.listpos);
evaluatePlaytime(data);
evaluateIsplaying(data.isplaying, data.listpos);
}
function evaluateListpos(listpos) {
if (previous_listpos != listpos) {
document.getElementById('timebar_mini').style.width = 0;
ajaxRequest('play.php?action=playlistTrack&track_id=' + track_id[listpos] + '&menu=playlist', evaluateTrack);
previous_miliseconds = 0;
previous_listpos = listpos;
}
else
hideSpinner();
}
function evaluateIsplaying(isplaying, idx) {
if (previous_isplaying != isplaying) {
if (isplaying.state){
idx = isplaying.idx;
isplaying = isplaying.state;
}
if (isplaying == 0) {
// stop
$("#time").removeClass();
$("#time").addClass("icon-anchor");
$("#play").removeClass();
$("#play").addClass("playlist_status_off");
$("#play").html('<i class="fa fa-play sign-ctrl"></i>');
$("#play").attr("onclick","javascript:ajaxRequest('play.php?action=play&menu=playlist', evaluateIsplaying);");
previous_miliseconds = 0;
}
else if (isplaying == 1) {
// play
$("#time").removeClass();
$("#time").addClass("icon-anchor");
$("#play").html('<i class="fa fa-pause sign-ctrl"></i>');
$("#play").removeClass();
$("#play").addClass("playlist_status_off");
$("#play").attr("onclick","javascript:ajaxRequest('play.php?action=pause&menu=playlist', evaluateIsplaying);");
}
else if (isplaying == 3) {
// pause
$("#time").removeClass();
$("#time").addClass("blink_me icon-anchor");
$("#play").html('<i class="fa fa-play sign-ctrl"></i>');
$("#play").removeClass();
$("#play").addClass("playlist_status_off");
$("#play").attr("onclick","javascript:ajaxRequest('play.php?action=play&menu=playlist', evaluateIsplaying);");
}
previous_isplaying = isplaying;
console.log('isplaying:' + isplaying + '; idx: ' + idx);
}
}
function evaluateTrackVersion(data) {
if (data.other_track_version) {
var track_ids = '';
for (var i = 0; i < data['track_ids'].length; i++) {
track_ids = track_ids + data['track_ids'][i] + ";";
};
other_title_enc = encodeURI(data['title']);
$('#track_title_mini').addClass('icon-anchor');
$('#title').addClass('icon-anchor');
$('#track_title_mini').click(function(){
window.location.href='index.php?action=view3all&track_ids=' + track_ids + '&other_title=' + other_title_enc;
}
);
$( "#title" ).click(function() {
$( "#track_title_mini" ).click();
})
}
}
function evaluateTrack(data) {
// data.artist, data.title, data.album, data.by, data.album_id, data.image_id
current_track_id = data.track_id;
if (previous_track_id != data.track_id && data.track_id != null) {
$('#track_title_mini').removeClass('icon-anchor');
$('#title').removeClass('icon-anchor');
$('#track_title_mini').off('click');
$('#title').off('click');
ajaxRequest('ajax-track-version.php?track_id=' + data.track_id + '&menu=playlist', evaluateTrackVersion);
previous_track_id = data.track_id;
}
var s = Math.floor(data.miliseconds / 1000);
var m = Math.floor(s / 60);
s = s % 60;
if (s < 10) s = '0' + s;
artist = '';
if ($.isArray(data.track_artist)) {
l = data.track_artist.length;
if (l>1) {
for (i=0; i<l; i++) {
artist = artist + '<a href="index.php?action=view2&order=year&sort=asc&artist=' + encodeURIComponent(data.track_artist_url[i]) + '">' + data.track_artist[i] + '</a>';
if (i!=l-1) {
var delimiter = data.track_artist_all.match(data.track_artist_url[i] + "(.*)" + data.track_artist_url[i+1]);
if (testing == 'on') {
delimiter[1] = delimiter[1].replace(';','&');
}
artist = artist + '<a href="index.php?action=view2&order=artist&sort=asc&artist=' + data.track_artist_url_all + '"><span class="artist_all">' + delimiter[1] + '</span></a>';
}
}
}
else if (l>0) {
//if (data.track_artist[0] != ' ') {
artist = '<a href="index.php?action=view2&order=year&sort=asc&artist=' + encodeURIComponent(data.track_artist_url[0]) + '">' + data.track_artist[0] + '</a>';
//}
}
}
else {
artist = '<a href="index.php?action=view2&order=year&sort=asc&artist=' + data.track_artist_url_all + '">' + data.track_artist + '</a>';
}
if (data.track_artist[0] == ' ') {
document.getElementById('artist_mini').innerHTML = ' ';
}
else {
document.getElementById('artist_mini').innerHTML = artist;
}
$("#artist_mini").show();
document.getElementById('track_title_mini').innerHTML = data.title;
var al = data.album;
if (data.album_id) {
var albumLink = '<a href="index.php?action=view3&album_id=' + data.album_id + '">' + data.album + '</a>';
document.getElementById('artist_mini').innerHTML = (data.album == ' ') ? ' ' : 'by ' + document.getElementById('artist_mini').innerHTML + ' from ' + albumLink;
}
else if (al.indexOf("://") > 0 && al.indexOf("://") < 6) {
//e.g. stream from youtube
var albumLink = '<a href="' + data.album + '" target="_new">' + data.album + '</a>';
document.getElementById('artist_mini').innerHTML = albumLink;
}
else if (data.relative_file && artist != '') {
var albumLink = 'by ' + artist + ' from ' + '<a href="browser.php?dir=' + data.relative_file + '">' + data.album + '</a>';
document.getElementById('artist_mini').innerHTML = albumLink;
}
else if (data.relative_file) {
var albumLink = '<a href="browser.php?dir=' + data.relative_file + '">' + data.album + '</a>';
document.getElementById('artist_mini').innerHTML = albumLink;
}
//else if (data.album != ' ' && artist != '' && data.totalTracks > 0) {
else if (data.album != ' ' && artist != '') {
document.getElementById('artist_mini').innerHTML = 'by ' + artist + ' from ' + data.album;
}
else if (data.album != ' ') {
document.getElementById('artist_mini').innerHTML = data.album;
}
else {
$("#artist_mini").hide();
}
console.log ('art: ' + artist);
if (data.album_id) {
$("#image_in_mini").attr("src","image.php?image_id=" + data.image_id + "&track_id=" + data.track_id);
}
else if (data.thumbnail) {
//thumbnail e.g. from Youtube
$("#image_in_mini").attr("src","image_crop.php?thumbnail=" + encodeURIComponent(data.thumbnail));
}
else {
document.getElementById('image_container_mini').innerHTML = '<a href="playlist.php"><img id="image_in_mini" src="<?php echo 'image/'; ?>large_file_not_found.png" alt=""></a>';
}
}
function evaluatePlaytime(data) {
// data.miliseconds, data.max, ....
if (previous_miliseconds != data.miliseconds) {
var width_ = 0;
var progress_bar_width = document.getElementById('info_area_mini').clientWidth;
if (data.Time > 0) width_ = Math.round(data.miliseconds / data.Time * progress_bar_width);
if (width_ > progress_bar_width) width_ = progress_bar_width;
$('#timebar_mini').width(width_);
previous_miliseconds = data.miliseconds;
}
}
$(document).ready(function() {
$('#play').longpress(function(e) {
ajaxRequest('play.php?action=stop&menu=playlist', evaluateIsplaying);
}, function(e) {
});
});
</script>