From 1e7684528e28aea6f30e31fa3f674d61e282df30 Mon Sep 17 00:00:00 2001 From: sigger Date: Thu, 2 Feb 2006 04:34:15 +0000 Subject: mpd mini-control for all pages! final ajax tweak? etc --- index.php | 9 ++-- lib/general.js | 24 +++++----- lib/general.lib.php | 11 +++++ modules/mpd/mpd.class.php | 8 +++- server/ajax.server.php | 8 ++-- templates/header.inc | 9 +++- templates/javascript_refresh.inc | 6 +-- templates/show_mpdminicontrol.inc | 95 +++++++++++++++++++++++++++++++++++++++ templates/show_mpdplay.inc | 9 ++-- 9 files changed, 149 insertions(+), 30 deletions(-) create mode 100644 templates/show_mpdminicontrol.inc diff --git a/index.php b/index.php index b858fe56..c7418049 100644 --- a/index.php +++ b/index.php @@ -28,12 +28,14 @@ require_once("modules/init.php"); -/* We need to attempt to init the mpd object */ +/* We need to attempt to init the mpd object if ($user->prefs['play_type']=='mpd') { $myMpd = init_mpd(); } +* Happening in header.inc now +*/ show_template('header'); -if (conf('refresh_limit') > 0) { show_template('javascript_refresh'); } +if (conf('refresh_limit') > 0) { require_once ("templates/javascript_refresh.inc"); } $action = scrub_in($_REQUEST['action']); ?> @@ -53,7 +55,8 @@ $action = scrub_in($_REQUEST['action']); prefs['play_type'] == 'mpd' && !conf('localplay_menu')) { + if (false) // $user->prefs['play_type'] == 'mpd' && !conf('localplay_menu')) +{ show_mpd_control(); } else { diff --git a/lib/general.js b/lib/general.js index 444029d2..ca86a667 100644 --- a/lib/general.js +++ b/lib/general.js @@ -56,12 +56,12 @@ function handleStateChange() { document.getElementById (new_state+'_button').className = "selected_button"; player_state = new_state; if (player_state == "stop" || player_state == "pause") { - document.getElementById ('mpd_np').className = "nodisplay"; -/* turn off the now playing stuff */ + if (document.getElementById ('mpd_np')) + document.getElementById ('mpd_np').className = "nodisplay"; } else { - document.getElementById ('mpd_np').className = ""; -/* turn on the now playing stuff */ + if (document.getElementById ('mpd_np')) + document.getElementById ('mpd_np').className = ""; } // end if else } // end if mpd changed player_state break; @@ -69,15 +69,17 @@ function handleStateChange() { ret_songid = Math.round(el.getElementsByTagName ('songid')[0].firstChild.data); if (player == 'mpd' && player_state != 'stop') { mpd_song_length = el.getElementsByTagName ('songlength')[0].firstChild.data; - document.getElementById ('mpd_npinfo').firstChild.data = - 1+ret_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 (document.getElementById ('mpd_npinfo')) { + document.getElementById ('mpd_npinfo').firstChild.data = + 1+ret_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 (ret_songid != mpd_songid) { - if (document.getElementById ('mpd_row'+mpd_songid) != null) { + if (document.getElementById ('mpd_row'+mpd_songid)) { if ((mpd_songid - mpdpl_first) %2 == 1) { document.getElementById ('mpd_row'+mpd_songid).className = 'even'; } else { diff --git a/lib/general.lib.php b/lib/general.lib.php index 9f985196..e485337f 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -901,4 +901,15 @@ function logout() { } // logout +/** + * format_time + * This formats seconds into minutes:seconds + */ + +function format_time($seconds) { + +return sprintf ("%d:%02d", $seconds/60, $seconds % 60); + +} //format_time + ?> diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index ed324ba3..2556f01b 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -838,11 +838,15 @@ class mpd { // Set Misc Other Variables $this->state = $status['state']; - if ( ($this->state == MPD_STATE_PLAYING) || ($this->state == MPD_STATE_PAUSED) ) { + if ($status['playlistlength']>0) { $this->current_track_id = $status['song']; + } else { + $this->current_track_id = -1; + } + if ( ($this->state == MPD_STATE_PLAYING) || ($this->state == MPD_STATE_PAUSED) ) { list ($this->current_track_position, $this->current_track_length ) = split(":",$status['time']); } else { - $this->current_track_id = -1; +// $this->current_track_id = -1; $this->current_track_position = -1; $this->current_track_length = -1; } diff --git a/server/ajax.server.php b/server/ajax.server.php index 71a36d27..b5b149b5 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -42,10 +42,10 @@ global $result, $myMpd; } $result = $result.''. ''.$myMpd->current_track_id.''. - ''.$myMpd->playlist[$myMpd->current_track_id]['Title'].''. - ''.$myMpd->playlist[$myMpd->current_track_id]['Artist'].''. - ''.$myMpd->playlist[$myMpd->current_track_id]['Album'].''. - ''.$myMpd->playlist[($myMpd->current_track_id)]['Time'].''. + ''.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Title']).''. + ''.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Artist']).''. + ''.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Album']).''. + ''.htmlspecialchars($myMpd->playlist[($myMpd->current_track_id)]['Time']).''. ''; } //end if player == mpd now_playing_display(); diff --git a/templates/header.inc b/templates/header.inc index d0ddff1e..514c2310 100644 --- a/templates/header.inc +++ b/templates/header.inc @@ -46,6 +46,10 @@ if (conf('use_rss')) { ?> Ampache: For the love of music + prefs['play_type']=='mpd') && ($location['page'] != 'mpd.php')) { + $myMpd = init_mpd(); + show_template ('show_mpdminicontrol'); + } else { ?>
Ampache v.
fullname; ?> @@ -59,11 +63,12 @@ if (conf('use_rss')) { ?> " class="button" /> -
+ +
- @@ -165,7 +164,7 @@ global $condPL; ". ".$myMpd->playlist[($myMpd->current_track_id+1)]['Artist']. " - ".$myMpd->playlist[($myMpd->current_track_id+1)]['Title']. " - ".$myMpd->playlist[($myMpd->current_track_id+1)]['Album']. - " - ".fmt_time($myMpd->playlist[($myMpd->current_track_id+1)]['Time']);?> + " - ".format_time($myMpd->playlist[($myMpd->current_track_id+1)]['Time']);?>
\ No newline at end of file +
diff --git a/templates/javascript_refresh.inc b/templates/javascript_refresh.inc index b0c5cd8b..92694bc4 100644 --- a/templates/javascript_refresh.inc +++ b/templates/javascript_refresh.inc @@ -61,11 +61,11 @@ function countdown() { if (displaycountdown==1) { window.status="Refreshing in "+reloadseconds+" seconds"; if ((player == 'mpd') && (player_state == 'play')) { - NodeList = document.getElementById ('mpd_cur_track_pos'); + if (NodeList = document.getElementById ('mpd_cur_track_pos')) { NodeList.firstChild.data = fmt_time((mpd_elapsed) + (secondssinceloaded)); } - NodeList = document.getElementById ('mpd_on_deck_in'); + if (NodeList = document.getElementById ('mpd_on_deck_in')) { NodeList.firstChild.data = fmt_time (mpd_song_length - mpd_elapsed - secondssinceloaded); } - NodeList = document.getElementById ('mpd_pctplayed'); + if (NodeList = document.getElementById ('mpd_pctplayed')) { NodeList.firstChild.data = Math.floor (100*(mpd_elapsed + secondssinceloaded)/mpd_song_length); } } if (reloadseconds > 0) { diff --git a/templates/show_mpdminicontrol.inc b/templates/show_mpdminicontrol.inc new file mode 100644 index 00000000..2319348f --- /dev/null +++ b/templates/show_mpdminicontrol.inc @@ -0,0 +1,95 @@ + + +
+ + + + +
+ + + + + + + + + + + +
+ state} = "class='selected_button'"; + if (true) /* rigged to do AJAX for now; change to conf('AJAX') later*/ { ?> + + + id="stop_button" value=" X " onclick="startRequest('action=stop');"/> + id="play_button" value=" > " onclick="startRequest('action=play');"/> + id="pause_button" value=" | | " onclick="startRequest('action=pause');"/> + + +
+ + " name="action" value="|< " /> + " name="action" value=" X " /> + " name="action" value=" > " /> + " name="action" value=" | | " /> + " name="action" value= " >|" /> +
+ +
+ Played current_track_position)?> + (current_track_position/$myMpd->current_track_length),2)*100)."%) of " . + format_time($myMpd->current_track_length); ?> + - Vol: volume ?>% + +
+ + + + + + + + [mute + -25 + -10 + +10 + +25] '; + +
+
+
diff --git a/templates/show_mpdplay.inc b/templates/show_mpdplay.inc index 30274a9c..fd9c942d 100644 --- a/templates/show_mpdplay.inc +++ b/templates/show_mpdplay.inc @@ -26,7 +26,6 @@ this looks a goodbit like local_play */ $web_path = conf('web_path'); -function fmt_time($seconds) {return sprintf ("%d:%02d", $seconds/60, $seconds % 60);} global $condPL; ?> @@ -135,20 +134,20 @@ global $condPL; ". ".$myMpd->playlist[$myMpd->current_track_id]['Artist']. " - ".$myMpd->playlist[$myMpd->current_track_id]['Title']. " - ".$myMpd->playlist[$myMpd->current_track_id]['Album']. - " - ".fmt_time($myMpd->playlist[$myMpd->current_track_id]['Time']); + " - ".format_time($myMpd->playlist[$myMpd->current_track_id]['Time']); echo ""; ?>
- current_track_position)?> + current_track_position)?> (current_track_position/$myMpd->current_track_length),2)*100)."%) played" ?>
".fmt_time($myMpd->current_track_length - $myMpd->current_track_position).")"?> + "".format_time($myMpd->current_track_length - $myMpd->current_track_position).")"?>
-- cgit