Commit 1e9659bf authored by Max Kellermann's avatar Max Kellermann

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.
parent 3be1cdf8
......@@ -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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment