aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist_state.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-25 19:45:57 +0100
committerMax Kellermann <max@duempel.org>2009-03-25 19:45:57 +0100
commit1e9659bf1f84dc260129007a17cc4bbe1d146ada (patch)
tree128117dc38aef469339b87f9b4ac2530608fcc4c /src/playlist_state.c
parent3be1cdf8e0488a933371a6a45ced720d2aa67905 (diff)
downloadmpd-1e9659bf1f84dc260129007a17cc4bbe1d146ada.tar.gz
mpd-1e9659bf1f84dc260129007a17cc4bbe1d146ada.tar.xz
mpd-1e9659bf1f84dc260129007a17cc4bbe1d146ada.zip
playlist_state: start playing after restore is complete
Don't start playback as soon as the "current" song is being loaded from the state file. That is unclean, and leads to an obscure bug: in repeat mode, when the song is started (which is yet the last song in the list), the playlist code marked the very first song in the playlist as "next" song, because the end of the playlist was wrapped. It's easier to set up the playback after all songs have been loaded, and after the random/repeat mode has been set.
Diffstat (limited to '')
-rw-r--r--src/playlist_state.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/playlist_state.c b/src/playlist_state.c
index 2b8f15ac8..698366b35 100644
--- a/src/playlist_state.c
+++ b/src/playlist_state.c
@@ -79,9 +79,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist)
}
static void
-playlist_state_load(FILE *fp, struct playlist *playlist,
- char *buffer,
- int state, int current, int seek_time)
+playlist_state_load(FILE *fp, struct playlist *playlist, char *buffer)
{
int song;
@@ -94,19 +92,6 @@ playlist_state_load(FILE *fp, struct playlist *playlist,
g_strchomp(buffer);
song = queue_load_song(&playlist->queue, buffer);
- if (song >= 0 && song == current) {
- if (state != PLAYER_STATE_STOP) {
- playPlaylist(playlist, queue_length(&playlist->queue) - 1);
- }
- if (state == PLAYER_STATE_PAUSE) {
- playerPause();
- }
- if (state != PLAYER_STATE_STOP) {
- seekSongInPlaylist(playlist,
- queue_length(&playlist->queue) - 1,
- seek_time);
- }
- }
if (!fgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) {
g_warning("'%s' not found in state file",
@@ -170,10 +155,24 @@ playlist_state_restore(FILE *fp, struct playlist *playlist)
PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) {
if (state == PLAYER_STATE_STOP)
current = -1;
- playlist_state_load(fp, playlist, buffer, state,
- current, seek_time);
+ playlist_state_load(fp, playlist, buffer);
}
}
setPlaylistRandomStatus(playlist, random_mode);
+
+ if (state != PLAYER_STATE_STOP && !queue_is_empty(&playlist->queue)) {
+ if (!queue_valid_position(&playlist->queue, current))
+ current = 0;
+
+ current = queue_position_to_order(&playlist->queue, current);
+
+ if (seek_time == 0)
+ playPlaylist(playlist, current);
+ else
+ seekSongInPlaylist(playlist, current, seek_time);
+
+ if (state == PLAYER_STATE_PAUSE)
+ playerPause();
+ }
}