From 1f5748db2b30825426e3b877699d86d543f641eb Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 15 Jan 2006 08:14:54 +0000 Subject: [PATCH] now playing stuff --- lib/general.js | 84 +++++++++++++++++++--- server/ajax.server.php | 116 +++++++++++++++++++++++------- templates/show_now_playing.inc | 126 +++++++++++++++++++++++---------- 3 files changed, 253 insertions(+), 73 deletions(-) diff --git a/lib/general.js b/lib/general.js index d196e8f0..c3cf40f6 100644 --- a/lib/general.js +++ b/lib/general.js @@ -15,7 +15,7 @@ function createXMLHttpRequest() { function startRequest(params) { createXMLHttpRequest(); xmlHttp.onreadystatechange = handleStateChange; - xmlHttp.open("GET", "server/ajax.server.php?"+params, true); + xmlHttp.open("GET", "server/ajax.server.php?"+params+"&player="+player, true); /* xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); */ xmlHttp.send(null); } @@ -27,7 +27,7 @@ alert ("mpd_elapsed ="+fmt_time(mpd_elapsed)+"; nowtime - starttime ="+fmt_time( function handleStateChange() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { -/* alert ("responseText = " + xmlHttp.responseText); */ +/* alert ("responseText = " + xmlHttp.responseText); */ var props = xmlHttp.responseXML.getElementsByTagName("properties")[0].childNodes; for (var i=1; i< props.length; i++) { @@ -38,7 +38,7 @@ function handleStateChange() { case 'action' : break; case 'volume' : var vol = el.firstChild.data; - document.getElementById ('volume').firstChild.data = vol; + if (player == 'mpd') document.getElementById ('volume').firstChild.data = vol; break; case 'mpd_cur_track_pos' : mpd_elapsed = Math.floor(el.firstChild.data); @@ -55,17 +55,17 @@ function handleStateChange() { document.getElementById (new_state+'_button').className = "selected_button"; player_state = new_state; if (player_state == "stop" || player_state == "pause") { - if (player == 'mpd') document.getElementById ('mpd_np').className = "nodisplay"; + document.getElementById ('mpd_np').className = "nodisplay"; /* turn off the now playing stuff */ } else { - if (player == 'mpd') document.getElementById ('mpd_np').className = ""; + document.getElementById ('mpd_np').className = ""; /* turn on the now playing stuff */ } // end if else - } // end if + } // end if mpd changed player_state break; case 'now_playing' : - if (player == 'mpd' && (player_state == 'play')) { + if (player == 'mpd' && player_state != 'stop') { 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 = @@ -74,8 +74,14 @@ function handleStateChange() { el.getElementsByTagName ('songtitle')[0].firstChild.data + " - " + el.getElementsByTagName ('songalbum')[0].firstChild.data + " - " + fmt_time(mpd_song_length); - } + } break; + case 'now_playing_display' : + // fix for pages where now playing data doesnt exist + if (document.getElementById('np_songid_0_holder')) { + show_now_playing_display(el); + } + break; default : alert ('Unknown XML reply :"'+el.tagName+'"'); } // end switch @@ -88,6 +94,68 @@ function handleStateChange() { } +// the actual function that checks and updates the now playing data. +function show_now_playing_display (el) { + for (var i=0; i' + + now_playing.getElementsByTagName('songtitle')[0].firstChild.data + ''; + + + // output the artist / album and link tags + document.getElementById('np_albumartist_'+i).innerHTML = + '' + + now_playing.getElementsByTagName('songalbum')[0].firstChild.data + + ' / ' + + now_playing.getElementsByTagName('songartist')[0].firstChild.data + ''; + + // output the album art, and the link for it + document.getElementById('np_img_'+i).innerHTML = + '' + + 'Album Art'; + + + // make sure its visible. + document.getElementById('np_container_'+i).style.display = 'block'; + + + } // end if holder = songid + } // for ecah record we get + + // fill in the rest with blank data and hide them. + while (i<5) { + document.getElementById('np_container_'+i).style.display = 'none'; + document.getElementById('np_songid_'+i+'_holder').innerHTML = ''; + i++; + } // end while i<5 + +} // end show_now_playing_display function + + function disableField(element) { var element_id = document.getElementById(element); element_id.disabled=true; diff --git a/server/ajax.server.php b/server/ajax.server.php index 445cfaf5..04394f45 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -4,28 +4,95 @@ header('Cache-control: no-cache'); header('Pragma: no-cache'); echo ''; -function mpderr() { global $result, $myMpd; $result = $result . ''.$myMpd->errStr.''; } -function volume() { global $result, $myMpd; $result = $result . ''. $myMpd->volume. ''; } -function state() { global $result, $myMpd; $result = $result. ''. $myMpd->state. ''; } -function mpd_cur_track_pos () { global $result, $myMpd; - $result = $result . ''.$myMpd->current_track_position.''; } +$no_session = true; +include ('../modules/init.php'); +$myMpd = init_mpd(); + +$action = $_GET['action']; +$player = $_GET['player']; +$result = ''; + + +function mpderr() { global $result, $myMpd; + if ($GLOBALS['player'] == 'mpd') + { $result = $result . ''.$myMpd->errStr.''; } } +function volume() { global $result, $myMpd; + if ($GLOBALS['player'] == 'mpd') + { $result = $result . ''. $myMpd->volume. ''; } } +function state() { global $result, $myMpd; + if ($GLOBALS['player'] == 'mpd') + { $result = $result. ''. $myMpd->state. ''; } } + +function mpd_cur_track_pos () { + global $result, $myMpd; + if ($GLOBALS['player'] == 'mpd') { + $result = $result . ''.$myMpd->current_track_position.''; + } +} function now_playing() { global $result, $myMpd; - if (!$myMpd->playlist[($myMpd->current_track_id)]['Title']) { - list($tmp, $id, $tmp) = preg_split("/(song=|&)/", $myMpd->playlist[($myMpd->current_track_id)]['file']); - $r = new Song($id); - $myMpd->playlist[($myMpd->current_track_id)]['Title'] = $r->title; - $myMpd->playlist[($myMpd->current_track_id)]['Artist'] = $r->get_artist_name(); - $myMpd->playlist[($myMpd->current_track_id)]['Album'] = $r->get_album_name(); - } - $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'].''. - ''; + if ($GLOBALS['player'] == 'mpd') { + if (!$myMpd->playlist[($myMpd->current_track_id)]['Title']) { + list($tmp, $id, $tmp) = preg_split("/(song=|&)/", $myMpd->playlist[($myMpd->current_track_id)]['file']); + $r = new Song($id); + $myMpd->playlist[($myMpd->current_track_id)]['Title'] = $r->title; + $myMpd->playlist[($myMpd->current_track_id)]['Artist'] = $r->get_artist_name(); + $myMpd->playlist[($myMpd->current_track_id)]['Album'] = $r->get_album_name(); + } + $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'].''. + ''; + } //end if player == mpd +now_playing_display(); +} + + +function now_playing_display() { + + global $result; + $dbh = dbh(); + $results = get_now_playing(); + $result = $result.''; + + if (count($results)) { + + foreach($results as $item) { + + $song = $item['song']; + $np_user = $item['user']; + + if (is_object($song)) { + + $result = $result.''; + + if (!$np_user->fullname) { $np_user->fullname = "Unknown User"; } + + if (conf('use_auth')) { + $result = $result.''.$np_user->fullname.''; + } else { + $result = $result.''; + } + + $result = $result.''.$song->id.''; + $result = $result.''.$song->album.''; + $result = $result.''.$song->artist.''; + $result = $result.''.htmlspecialchars($song->f_title).''; + $result = $result.''.htmlspecialchars($song->f_artist).''; + $result = $result.''.htmlspecialchars($song->f_album).''; + + $result = $result.''; + + } // if it's a song + } // foreach song + + } // if now playing + $result = $result.''; + } @@ -38,13 +105,6 @@ instantiation of myMpd. Would be much faster if it only loaded limited info to just grabbed what it needed. (Prolly tougher to maintain abstraction.) **********************/ -$no_session = true; -include ('../modules/init.php'); -$myMpd = init_mpd(); - -$action = $_GET['action']; -$result = ''; - /*if (!$user->has_access(25)) { echo 'Inadequate access privileges!'; return; }*/ switch ($action) { @@ -70,6 +130,7 @@ case 'adjvol' : case ' X ': if ( is_null($myMpd->Stop()) ) $result = ''.$myMpd->errStr.'\n'; $result = $result.''. $myMpd->state. ''; + now_playing(); break; case ' | | ': case ' = ': @@ -96,6 +157,7 @@ case 'adjvol' : mpd_cur_track_pos(); state(); now_playing(); +// now_playing_display(); break; @@ -103,7 +165,7 @@ case 'adjvol' : echo '' . - '' . $action .'' . + '' . $action .$player.'' . $result . ''; ?> diff --git a/templates/show_now_playing.inc b/templates/show_now_playing.inc index e294510b..737e6ce7 100644 --- a/templates/show_now_playing.inc +++ b/templates/show_now_playing.inc @@ -19,47 +19,97 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*! + @header Show Now Playing Ajax +*/ + + +// would change this to input some with the current now playing data. +// so this same script can be used even if the ajax doesnt refresh it. ?> - +'; + if (!$np_user->fullname) { $np_user->fullname = "Unknown User"; } + if (conf('use_auth')) { + $result = $result.''.$np_user->fullname.''; + } + else { + $result = $result.''; + } +?> +
+ - + -f_artist; - $album = $song->get_album_name(); - $text = "$song->f_title"; - if (!$np_user->fullname) { $np_user->fullname = "Unknown User"; } - if ($GLOBALS['user']->username == $np_user->username) { - $sql = "SELECT start_time FROM now_playing WHERE user ='".$user->username."'"; - $db_results = mysql_query($sql, dbh()); - echo "\n"; - } else { - echo "\n"; - } - if (conf('use_auth')) { - echo "\t\n"; - } - echo "\t\n"; - echo "\t"; - if (conf('play_album_art')) { - echo "\t\n"; - echo "\n"; - } // if album art on now playing - else { echo "\n"; } - } // if it's a song -} // while we're getting songs -?>
$np_user->fullnametitle) . "\" href=\"$web_path/song.php?action=m3u&song=$song->id\">$textf_artist) . "\" href=\"$web_path/artists.php?action=show&artist=$song->artist\">$song->f_artist / "; - echo "\talbum\">$song->f_album"; - $aa_url = $web_path . "/albumart.php?id=$song->album&type=popup"; - echo ""; - echo "album&fast=1&thumb=1\" alt=\"Album Art\" height=\"75\" />"; - echo "\n"; - echo "\t
+ + + + + + + +
+ +
+ fullname; } ?>
+
+ + + + +
+ + Album Art + +
+
+
+ + + + +
+