author | Dan |
Sun, 23 Mar 2008 20:24:33 -0400 | |
changeset 2 | 860ba7141641 |
parent 0 | c63de9eb7045 |
child 3 | e7447a6044ec |
permissions | -rw-r--r-- |
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
1 |
/** |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
2 |
* AJAX functions |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
3 |
* |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
4 |
* Web control interface script for Amarok |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
5 |
* Written by Dan Fuhry - 2008 |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
6 |
* |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
7 |
* This script is in the public domain. Use it for good, not evil. |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
8 |
*/ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
9 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
10 |
var ajax; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
11 |
var is_playing = false, current_track = -1, current_track_length, current_track_pos, ct_advance_timeout = false, ct_counter = false, playlist_md5 = false; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
12 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
13 |
function ajaxGet(uri, f) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
14 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
15 |
if (window.XMLHttpRequest) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
16 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
17 |
ajax = new XMLHttpRequest(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
18 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
19 |
else |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
20 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
21 |
if (window.ActiveXObject) { |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
22 |
ajax = new ActiveXObject("Microsoft.XMLHTTP"); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
23 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
24 |
else |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
25 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
26 |
alert('AmaroK client-side runtime error: No AJAX support, unable to continue'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
27 |
return; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
28 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
29 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
30 |
ajax.onreadystatechange = f; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
31 |
ajax.open('GET', uri, true); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
32 |
ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" ); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
33 |
ajax.send(null); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
34 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
35 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
36 |
function ajaxPost(uri, parms, f) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
37 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
38 |
if (window.XMLHttpRequest) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
39 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
40 |
ajax = new XMLHttpRequest(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
41 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
42 |
else |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
43 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
44 |
if (window.ActiveXObject) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
45 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
46 |
ajax = new ActiveXObject("Microsoft.XMLHTTP"); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
47 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
48 |
else |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
49 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
50 |
alert('AmaroK client-side runtime error: No AJAX support, unable to continue'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
51 |
return; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
52 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
53 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
54 |
ajax.onreadystatechange = f; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
55 |
ajax.open('POST', uri, true); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
56 |
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
57 |
// Setting Content-length in Safari triggers a warning |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
58 |
if ( !is_Safari ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
59 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
60 |
ajax.setRequestHeader("Content-length", parms.length); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
61 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
62 |
ajax.setRequestHeader("Connection", "close"); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
63 |
ajax.send(parms); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
64 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
65 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
66 |
function setAjaxLoading() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
67 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
68 |
$('ajax_status').object.src = img_ajax; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
69 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
70 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
71 |
function unsetAjaxLoading() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
72 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
73 |
$('ajax_status').object.src = 'about:blank'; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
74 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
75 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
76 |
var refresh_playlist = function() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
77 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
78 |
setAjaxLoading(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
79 |
ajaxGet('/action.json/refresh', function() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
80 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
81 |
if ( ajax.readyState == 4 && ajax.status == 200 ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
82 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
83 |
unsetAjaxLoading(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
84 |
var response = (' ' + ajax.responseText).substr(1); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
85 |
// quickie JSON parser :) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
86 |
response = eval('(' + response + ')'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
87 |
// has the playlist been modified? |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
88 |
if ( playlist_md5 ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
89 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
90 |
if ( response.playlist_hash != playlist_md5 ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
91 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
92 |
// playlist has changed, reload |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
93 |
window.location.reload(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
94 |
return false; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
95 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
96 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
97 |
playlist_md5 = response.playlist_hash; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
98 |
// update track number |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
99 |
if ( response.current_track != current_track ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
100 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
101 |
var ot_id = 'track_' + current_track; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
102 |
var nt_id = 'track_' + response.current_track; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
103 |
current_track = response.current_track; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
104 |
if ( $(ot_id).hasClass('current') ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
105 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
106 |
$(ot_id).rmClass('current'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
107 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
108 |
if ( ! $(nt_id).hasClass('current') ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
109 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
110 |
$(nt_id).addClass('current'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
111 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
112 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
113 |
// update playing status |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
114 |
var img = $('btn_playpause').object.getElementsByTagName('img')[0]; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
115 |
is_playing = response.is_playing; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
116 |
if ( is_playing ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
117 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
118 |
img.src = img_pause; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
119 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
120 |
else |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
121 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
122 |
img.src = img_play; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
123 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
124 |
// update volume |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
125 |
if ( response.volume != current_volume ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
126 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
127 |
set_volume_fill(response.volume); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
128 |
current_volume = response.volume; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
129 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
130 |
// auto-refresh on track advance |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
131 |
if ( ct_advance_timeout ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
132 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
133 |
clearTimeout(ct_advance_timeout); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
134 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
135 |
var time_remaining = response.current_track_length - response.current_track_pos; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
136 |
current_track_length = response.current_track_length; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
137 |
current_track_pos = response.current_track_pos; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
138 |
if ( ct_counter ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
139 |
clearInterval(ct_counter); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
140 |
update_clock(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
141 |
if ( is_playing ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
142 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
143 |
ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining )); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
144 |
ct_counter = setInterval(update_clock, 1000); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
145 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
146 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
147 |
}); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
148 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
149 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
150 |
function player_action(action) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
151 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
152 |
var act2 = action; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
153 |
setAjaxLoading(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
154 |
ajaxGet('/action.json/' + action, function() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
155 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
156 |
if ( ajax.readyState == 4 && ajax.status == 200 ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
157 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
158 |
unsetAjaxLoading(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
159 |
refresh_playlist(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
160 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
161 |
}); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
162 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
163 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
164 |
function jump_to_song(tid) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
165 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
166 |
setAjaxLoading(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
167 |
if ( tid == current_track ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
168 |
return false; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
169 |
ajaxGet('/action.json/jump/' + tid, function() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
170 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
171 |
if ( ajax.readyState == 4 && ajax.status == 200 ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
172 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
173 |
unsetAjaxLoading(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
174 |
var response = (' ' + ajax.responseText).substr(1); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
175 |
// quickie JSON parser :) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
176 |
response = eval('(' + response + ')'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
177 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
178 |
// update track number |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
179 |
var ot_id = 'track_' + current_track; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
180 |
var nt_id = 'track_' + tid; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
181 |
current_track = tid; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
182 |
if ( $(ot_id).hasClass('current') ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
183 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
184 |
$(ot_id).rmClass('current'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
185 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
186 |
if ( ! $(nt_id).hasClass('current') ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
187 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
188 |
$(nt_id).addClass('current'); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
189 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
190 |
// update playing status |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
191 |
var img = $('btn_playpause').object.getElementsByTagName('img')[0]; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
192 |
is_playing = true; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
193 |
img.src = img_play; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
194 |
// auto-refresh on track advance |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
195 |
if ( ct_advance_timeout ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
196 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
197 |
clearTimeout(ct_advance_timeout); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
198 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
199 |
if ( ct_counter ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
200 |
clearInterval(ct_counter); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
201 |
var time_remaining = response.current_track_length - response.current_track_pos; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
202 |
current_track_length = response.current_track_length; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
203 |
current_track_pos = response.current_track_pos; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
204 |
if ( is_playing ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
205 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
206 |
ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining )); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
207 |
update_clock(); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
208 |
ct_counter = setInterval(update_clock, 1000); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
209 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
210 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
211 |
}); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
212 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
213 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
214 |
function update_clock() |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
215 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
216 |
var str = secs_to_string(current_track_pos) + '/' + secs_to_string(current_track_length); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
217 |
$('playmeter').object.innerHTML = str; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
218 |
current_track_pos++; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
219 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
220 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
221 |
function secs_to_string(time) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
222 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
223 |
var count_seconds = time % 60; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
224 |
var count_minutes = ( time - count_seconds ) / 60; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
225 |
return fill_zeroes(count_minutes) + ':' + fill_zeroes(count_seconds); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
226 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
227 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
228 |
function fill_zeroes(str, len) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
229 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
230 |
if ( !len ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
231 |
len = 2; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
232 |
if ( typeof(str) == 'number' && str == 0 ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
233 |
str = '0'; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
234 |
str = String(str); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
235 |
while ( str.length < len ) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
236 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
237 |
str = '0' + str; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
238 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
239 |
return str; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
240 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
241 |
|
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
242 |
window.onload = refresh_playlist; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
243 |
setInterval(refresh_playlist, 10000); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
244 |