From 1e9659bf1f84dc260129007a17cc4bbe1d146ada Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 25 Mar 2009 19:45:57 +0100 Subject: 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. --- src/playlist_state.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src') 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(); + } } -- cgit v1.2.3