Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
--- a/ajax.php Sat Apr 12 09:26:01 2008 -0400
+++ b/ajax.php Fri Apr 25 12:42:26 2008 -0400
@@ -76,7 +76,10 @@
dcop_action('playlist', "playByIndex $tid");
$return = array(
'current_track_length' => $playlist[$tid]['length_int'],
- 'current_track_pos' => 0
+ 'current_track_pos' => 0,
+ 'current_track_title' => $playlist[$tid]['title'],
+ 'current_track_album' => $playlist[$tid]['album'],
+ 'current_track_artist' => $playlist[$tid]['artist']
);
echo $json->encode($return);
break;
@@ -120,12 +123,18 @@
'volume' => dcop_action('player', 'getVolume'),
// include the MD5 of the playlist so that if it changes, the
// client can refresh (otherwise things get madly corrupted)
- 'playlist_hash' => $playlist_last_md5
+ 'playlist_hash' => $playlist_last_md5,
+ 'current_track_title' => false,
+ 'current_track_album' => false,
+ 'current_track_artist' => false
);
if ( isset($playlist[$current_track]) )
{
$return['current_track_length'] = $playlist[$current_track]['length_int'];
$return['current_track_pos'] = dcop_action('player', 'trackCurrentTime');
+ $return['current_track_title'] = $playlist[$current_track]['title'];
+ $return['current_track_artist'] = $playlist[$current_track]['artist'];
+ $return['current_track_album'] = $playlist[$current_track]['album'];
}
echo $json->encode($return);
break;
--- a/scripts/ajax.js Sat Apr 12 09:26:01 2008 -0400
+++ b/scripts/ajax.js Fri Apr 25 12:42:26 2008 -0400
@@ -175,12 +175,24 @@
{
clearTimeout(ct_advance_timeout);
}
+ // countdown/up timer
var time_remaining = response.current_track_length - response.current_track_pos;
current_track_length = response.current_track_length;
current_track_pos = response.current_track_pos;
if ( ct_counter )
clearInterval(ct_counter);
update_clock();
+
+ // set page title
+ updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
+
+ // if not playing, set the position slider to zero
+ if ( !is_playing )
+ {
+ posslide_set_position(0);
+ }
+
+ // set advance timer
if ( is_playing && time_remaining > 0 )
{
ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
@@ -259,6 +271,7 @@
update_clock();
ct_counter = setInterval(update_clock, 1000);
}
+ updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
}
});
}
@@ -403,3 +416,26 @@
addOnloadHook(pulsar_reset);
setInterval(pulsar_advance, 50);
+function updateTitle(artist, album, track)
+{
+ var sep = '';
+ var str = '';
+ if ( track )
+ {
+ str += sep + track;
+ sep = ' - ';
+ }
+ if ( artist )
+ {
+ str += sep + artist;
+ sep = ' - ';
+ }
+ if ( album )
+ {
+ str += sep + album;
+ sep = ' - ';
+ }
+ str += sep + 'AmaroK Playlist';
+ document.title = str;
+}
+
--- a/themes/iphone/playlist.tpl Sat Apr 12 09:26:01 2008 -0400
+++ b/themes/iphone/playlist.tpl Fri Apr 25 12:42:26 2008 -0400
@@ -62,7 +62,7 @@
</div>
</div>
<div class="tblholder" id="playlist">
- <table border="0" cellspacing="1" cellpadding="4">
+ <table border="0" cellspacing="1" cellpadding="4" style="width: 100%;">
<tr>
<th>Track</th>
</tr>