summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigger <sigger@ampache>2006-01-08 18:15:09 +0000
committersigger <sigger@ampache>2006-01-08 18:15:09 +0000
commit373255aadcf56ca795c6fca0f41504ec4f468681 (patch)
tree292427d05d63d086c2790c09e3162df40008e85f
parent58d139eb26220d1faf7025f303fee735e883f344 (diff)
downloadampache-373255aadcf56ca795c6fca0f41504ec4f468681.tar.gz
ampache-373255aadcf56ca795c6fca0f41504ec4f468681.tar.bz2
ampache-373255aadcf56ca795c6fca0f41504ec4f468681.zip
(mostly) fixes ajax and nowplaying JS
-rw-r--r--lib/general.js35
-rw-r--r--lib/general.lib.php1
-rw-r--r--mpd.php1
-rw-r--r--server/ajax.server.php4
-rw-r--r--templates/javascript_refresh.inc27
-rw-r--r--templates/show_mpdplay.inc6
-rw-r--r--templates/show_now_playing.inc1
7 files changed, 47 insertions, 28 deletions
diff --git a/lib/general.js b/lib/general.js
index bfa97821..879da45a 100644
--- a/lib/general.js
+++ b/lib/general.js
@@ -2,6 +2,7 @@
var xmlHttp;
var requestType="";
+
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
@@ -48,32 +49,32 @@ function handleStateChange() {
case 'state' :
var new_state = el.firstChild.data;
-/* alert ('state = '+new_state+'; mpd_state = '+mpd_state); */
- if (mpd_state != new_state) {
- document.getElementById (mpd_state+'_button').className = "";
+/* alert ('state = '+new_state+'; player_state = '+player_state); */
+ if ((player == 'mpd') && (player_state != new_state)) {
+ document.getElementById (player_state+'_button').className = "";
document.getElementById (new_state+'_button').className = "selected_button";
- mpd_state = new_state;
- if (mpd_state == "stop" || mpd_state == "pause") {
- mpd_notstoppause = 0;
- document.getElementById ('mpd_np').className = "nodisplay";
+ player_state = new_state;
+ if (player_state == "stop" || player_state == "pause") {
+ if (player == 'mpd') document.getElementById ('mpd_np').className = "nodisplay";
/* turn off the now playing stuff */
} else
{
- mpd_notstoppause = 1;
- document.getElementById ('mpd_np').className = "";
+ if (player == 'mpd') document.getElementById ('mpd_np').className = "";
/* turn on the now playing stuff */
} // end if else
} // end if
break;
case 'now_playing' :
- mpd_song_length = el.getElementsByTagName ('songlength')[0].firstChild.data;
- mpd_songid = Math.round(el.getElementsByTagName ('songid')[0].firstChild.data);
- document.getElementById ('mpd_npinfo').firstChild.data =
- 1+mpd_songid + ". " +
- el.getElementsByTagName ('songartist')[0].firstChild.data + " - " +
- el.getElementsByTagName ('songtitle')[0].firstChild.data + " - " +
- el.getElementsByTagName ('songalbum')[0].firstChild.data + " - " +
- fmt_time(mpd_song_length);
+ if (player == 'mpd') {
+ mpd_song_length = el.getElementsByTagName ('songlength')[0].firstChild.data;
+ mpd_songid = Math.round(el.getElementsByTagName ('songid')[0].firstChild.data);
+ document.getElementById ('mpd_npinfo').firstChild.data =
+ 1+mpd_songid + ". " +
+ el.getElementsByTagName ('songartist')[0].firstChild.data + " - " +
+ el.getElementsByTagName ('songtitle')[0].firstChild.data + " - " +
+ el.getElementsByTagName ('songalbum')[0].firstChild.data + " - " +
+ fmt_time(mpd_song_length);
+ }
break;
default :
alert ('Unknown XML reply :"'+el.tagName+'"');
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 983b4c12..0a308b64 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -81,6 +81,7 @@ function int2ip($i) {
@param $template Name of Template
*/
function show_template($template) {
+global $myMpd, $user;
/* Check for a 'Theme' template */
if (is_readable(conf('prefix') . conf('theme_path') . "/templates/$template".".inc")) {
diff --git a/mpd.php b/mpd.php
index ca495fe8..be667ebc 100644
--- a/mpd.php
+++ b/mpd.php
@@ -26,6 +26,7 @@
*/
require_once("modules/init.php");
+$myMpd = init_mpd();
show_template('header');
if (conf('refresh_limit') > 0) { show_template('javascript_refresh'); }
diff --git a/server/ajax.server.php b/server/ajax.server.php
index f0489727..445cfaf5 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -102,8 +102,8 @@ case 'adjvol' :
} //end switch
-echo '<properties>
- <action>' . $action .'</action>' .
+echo '<properties>' .
+ '<action>' . $action .'</action>' .
$result .
'</properties>';
?>
diff --git a/templates/javascript_refresh.inc b/templates/javascript_refresh.inc
index a7ccff43..974092d0 100644
--- a/templates/javascript_refresh.inc
+++ b/templates/javascript_refresh.inc
@@ -1,12 +1,26 @@
<script type="text/javascript" language="javascript">
<!-- Begin
-// JS variables mpd_elapsed, mpd_song_length and mpd_state set in show_mpdplay.inc
// when a page/song is loaded, we get starttime and mpd_elapsed.
// mpd_elapsed is # of seconds elapsed in the now playing song when the page/song was refreshed
+// secondssinceloaded is the calculated number of seconds since mpd_elapsed was set (less some load & execute lag).
// Set refresh interval (in seconds)
var refreshinterval=<?php echo conf('refresh_limit'); ?>
+<?php
+if ($user->prefs['play_type'] == 'mpd') {
+ echo 'var player = "mpd"' .
+ '; var mpd_elapsed = '. $myMpd->current_track_position .
+ '; var mpd_song_length = '. $myMpd->current_track_length .
+ '; var mpd_songid = '.$myMpd->current_track_id.
+ '; var player_state = "'. $myMpd->state .'";';
+} else {
+ echo 'var player = "'. $user->prefs['play_type'] .
+ '"; var player_state = "";';
+}
+?>
+
+
// Display the countdown inside the status bar?
// Set "1" for yes or "0" for no
var displaycountdown=1
@@ -16,20 +30,17 @@ var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0
-var mpd_notstoppause=1
+//var mpd_notstoppause=1
function starttime() {
starttime=new Date()
starttime=starttime.getTime()
- if (mpd_state == "stop" || mpd_state == "pause") { mpd_notstoppause = 0; }
+// if (player_state == "stop" || player_state == "pause") { mpd_notstoppause = 0; }
countdown()
}
function fmt_time (timenum) {
var sec = Math.floor(timenum % 60);
-/*var min = Math.floor(timenum / 60);
-var fmted = min + ':' + ((sec < 10) ? "0" : "") + sec ;
-return fmted;*/
return Math.floor((1/60) * timenum) + ':' + ((sec < 10) ? '0' : '') + sec;
}
@@ -39,7 +50,7 @@ function countdown() {
nowtime=nowtime.getTime()
secondssinceloaded=(nowtime-starttime)/1000
- if (mpd_notstoppause) {
+ if (player_state == 'play') {
reloadseconds = Math.round(mpd_song_length - mpd_elapsed - secondssinceloaded)
}
else
@@ -47,7 +58,7 @@ function countdown() {
if (displaycountdown==1) {
window.status="Refreshing in "+reloadseconds+" seconds";
- if (mpd_notstoppause) {
+ if ((player == 'mpd') && (player_state = 'play')) {
NodeList = document.getElementById ('mpd_cur_track_pos');
{ NodeList.firstChild.data = fmt_time((mpd_elapsed) + (secondssinceloaded)); }
NodeList = document.getElementById ('mpd_on_deck_in');
diff --git a/templates/show_mpdplay.inc b/templates/show_mpdplay.inc
index 4b9f9e03..fa106c08 100644
--- a/templates/show_mpdplay.inc
+++ b/templates/show_mpdplay.inc
@@ -187,10 +187,16 @@ else {
</td></tr>
</table>
<?php
+/***** moving this into javascript_refresh.js
+
echo '<script language="JavaScript" type="text/javascript"> var mpd_elapsed = '. $myMpd->current_track_position.
'; var mpd_song_length = '. $myMpd->current_track_length .
'; var mpd_songid = '.$myMpd->current_track_id.
'; var mpd_state = "'. $myMpd->state .'"; </script>';
+
+****** end move
+******/
+
?>
</div>
diff --git a/templates/show_now_playing.inc b/templates/show_now_playing.inc
index 193a469f..7865327c 100644
--- a/templates/show_now_playing.inc
+++ b/templates/show_now_playing.inc
@@ -32,7 +32,6 @@
</tr>
<?php
$user = $GLOBALS['user'];
- echo '<script language="JavaScript" type="text/javascript"> var mpd_state = "'. "stop" .'" </script>';
foreach($results as $item) {
$song = $item['song'];
$np_user = $item['user'];