summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigger <sigger@ampache>2006-02-02 04:34:15 +0000
committersigger <sigger@ampache>2006-02-02 04:34:15 +0000
commit1e7684528e28aea6f30e31fa3f674d61e282df30 (patch)
treed43678e0104f8a299663779f0c9d23799d885bc3
parent27847d72ca91c107a1f74cb1e072e58c9cbe7b8f (diff)
downloadampache-1e7684528e28aea6f30e31fa3f674d61e282df30.tar.gz
ampache-1e7684528e28aea6f30e31fa3f674d61e282df30.tar.bz2
ampache-1e7684528e28aea6f30e31fa3f674d61e282df30.zip
mpd mini-control for all pages! final ajax tweak? etc
-rw-r--r--index.php9
-rw-r--r--lib/general.js24
-rw-r--r--lib/general.lib.php11
-rw-r--r--modules/mpd/mpd.class.php8
-rw-r--r--server/ajax.server.php8
-rw-r--r--templates/header.inc9
-rw-r--r--templates/javascript_refresh.inc6
-rw-r--r--templates/show_mpdminicontrol.inc95
-rw-r--r--templates/show_mpdplay.inc9
9 files changed, 149 insertions, 30 deletions
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']);
</td>
<td valign="top" align="left"> <!-- sigger: why is it a problem to set width=50% -->
<?php
- if ($user->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.'<now_playing>'.
'<songid>'.$myMpd->current_track_id.'</songid>'.
- '<songtitle>'.$myMpd->playlist[$myMpd->current_track_id]['Title'].'</songtitle>'.
- '<songartist>'.$myMpd->playlist[$myMpd->current_track_id]['Artist'].'</songartist>'.
- '<songalbum>'.$myMpd->playlist[$myMpd->current_track_id]['Album'].'</songalbum>'.
- '<songlength>'.$myMpd->playlist[($myMpd->current_track_id)]['Time'].'</songlength>'.
+ '<songtitle>'.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Title']).'</songtitle>'.
+ '<songartist>'.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Artist']).'</songartist>'.
+ '<songalbum>'.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Album']).'</songalbum>'.
+ '<songlength>'.htmlspecialchars($myMpd->playlist[($myMpd->current_track_id)]['Time']).'</songlength>'.
'</now_playing>';
} //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')) { ?>
<img class="pageheader" src="<?php echo $web_path; ?><?php echo conf('theme_path'); ?>/images/ampache.gif" border="0" title="Ampache: For the love of music" alt="Ampache: For the love of music" />
</a>
</div><!--End topbarleft -->
+ <?php if (($user->prefs['play_type']=='mpd') && ($location['page'] != 'mpd.php')) {
+ $myMpd = init_mpd();
+ show_template ('show_mpdminicontrol');
+ } else { ?>
<div id="topbarright">
<a href="http://www.ampache.org/index.php">Ampache v.<?php echo conf('version'); ?></a><br />
<b><?php echo _("You are currently logged in as") . " " . $GLOBALS['user']->fullname; ?></b>
@@ -59,11 +63,12 @@ if (conf('use_rss')) { ?>
</select>
<input type="submit" value="<?php echo _("Go!"); ?>" class="button" />
</form>
- </div><!-- End topbarright -->
+ </div> <!-- End topbarright -->
+ <?php } ?>
</div><!-- End topbar -->
<div id="sidebar"><!-- This is the sidebar -->
<?php require_once(conf('prefix') . '/templates/sidebar.inc.php'); ?>
</div><!-- End sidebar -->
<div id="content">
<table> <!-- Start Main Page Table-->
-<tr><td> \ No newline at end of file
+<tr><td>
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 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2005 Ampache.org
+ All rights reserved.
+
+ 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 2
+ 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+/*!
+ @header Show mpd controls, this doesn't
+ include the playlist, status and what have you.
+ this looks a goodbit like local_play
+*/
+$web_path = conf('web_path');
+require_once ("javascript_refresh.inc");
+?>
+
+<div align="center"><!-- Is this div neccesary??? or is the below table not needed???-->
+<table border="0" cellpadding="3" cellspacing="0"><!-- MPD Control table -->
+<tr>
+<td>
+ <table id="mpd_control" border="0" cellpadding="0" cellspacing="0" class="even" align="center">
+<!-- <th class="table-header"><?php echo _("MPD Play Control"); ?></th> -->
+ <tr>
+ <td>
+ <?php ${$myMpd->state} = "class='selected_button'";
+ if (true) /* rigged to do AJAX for now; change to conf('AJAX') later*/ { ?>
+ <!-- for testing <input type="button" value="times" onclick="timestuff();"/> -->
+ <input type="button" value="|&lt; " onclick="startRequest('action=Prev');"/>
+ <input type="button" <?php echo $stop ?> id="stop_button" value=" X " onclick="startRequest('action=stop');"/>
+ <input type="button" <?php echo $play ?> id="play_button" value=" &gt; " onclick="startRequest('action=play');"/>
+ <input type="button" <?php echo $pause ?> id="pause_button" value=" | | " onclick="startRequest('action=pause');"/>
+ <input type="button" value=" &gt;|" onclick="startRequest('action=Next');"/>
+ <?php
+ }
+ else { ?>
+ <form action="<?php echo $web_path; ?>/amp-mpd.php" method="post" name="playcontrol" style="display:inline; white-space: nowrap">
+ <!-- these used to have class="button" -->
+ <input type="submit" title="<?php echo _("Prev"); ?>" name="action" value="|&lt; " />
+ <input type="submit" title="<?php echo _("Stop"); ?>" name="action" value=" X " <?php echo $stop; ?> />
+ <input type="submit" title="<?php echo _("Play"); ?>" name="action" value=" &gt; " <?php echo $play; ?> />
+ <input type="submit" title="<?php echo _("Pause"); ?>" name="action" value=" | | " <?php echo $pause; ?> />
+ <input type="submit" title="<?php echo _("Next"); ?>" name="action" value= " &gt;|" />
+ </form>
+ <?php } ?>
+ </td>
+ </tr>
+ <tr>
+ <td class="content">
+ Played <b><span id="mpd_cur_track_pos"><?php echo format_time($myMpd->current_track_position)?></span></b>
+ (<span id="mpd_pctplayed"><?php echo (round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."</span>%) of " .
+ format_time($myMpd->current_track_length); ?>
+ - Vol: <b><span id='volume'><?php echo $myMpd->volume ?></span>%</b>
+
+</td>
+ </tr>
+ <tr>
+ <td class="content">
+ <?php
+ if (true) /* rigged to do AJAX for now; change to conf('AJAX') later */ { ?>
+ <input type="button" value="0" onclick="startRequest('action=setvol&amp;param1=0');"/>
+ <input type="button" value="-25" onclick="startRequest('action=adjvol&amp;param1=-25');"/>
+ <input type="button" value="-10" onclick="startRequest('action=adjvol&amp;param1=-10');"/>
+ <input type="button" value="+10" onclick="startRequest('action=adjvol&amp;param1=10');"/>
+ <input type="button" value="+25" onclick="startRequest('action=adjvol&amp;param1=25');"/>
+ <?php
+ }
+ else { ?>
+ [<a href="<?php echo $web_path; ?>/amp-mpd.php?action=setvol&amp;val=0">mute</a>
+ <a href="<?php echo $web_path; ?>/amp-mpd.php?action=adjvol&amp;val=-25">-25</a>
+ <a href="<?php echo $web_path; ?>/amp-mpd.php?action=adjvol&amp;val=-10">-10</a>
+ <a href="<?php echo $web_path; ?>/amp-mpd.php?action=adjvol&amp;val=+10">+10</a>
+ <a href="<?php echo $web_path; ?>/amp-mpd.php?action=adjvol&amp;val=+25">+25</a>] ';
+ <?php } ?>
+ </td>
+ </tr>
+ </table>
+</td>
+</tr>
+</table>
+</div>
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 "</span>"; ?>
</td>
</tr>
<tr>
<td align="center" class="npsong">
- <span id="mpd_cur_track_pos"><?php echo fmt_time($myMpd->current_track_position)?></span>
+ <span id="mpd_cur_track_pos"><?php echo format_time($myMpd->current_track_position)?></span>
(<span id="mpd_pctplayed"><?php echo (round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."</span>%) played" ?>
</td>
</tr>
<tr>
<td>
<b><?php echo _("On Deck ")?><?php echo _("(in ").
- "<span id = 'mpd_on_deck_in'>".fmt_time($myMpd->current_track_length - $myMpd->current_track_position)."</span>)"?>
+ "<span id = 'mpd_on_deck_in'>".format_time($myMpd->current_track_length - $myMpd->current_track_position)."</span>)"?>
</b>
</td>
</tr>
@@ -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']);?>
</td>
</tr>
</table>