From 9da7ae02f06cfd90897b6e0c87619f546675b2e9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 23 Jan 2009 00:10:38 +0100 Subject: playlist: restart playing in deleteFromPlaylist() When a song is deleted, start playing the next song immediately, within deleteFromPlaylist(). This allows us to remove the ugly playlist_noGoToNext flag, and the currentSongInPlaylist() function. --- src/playlist.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/playlist.c b/src/playlist.c index 9a6347770..2b8af836d 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -70,7 +70,6 @@ static Playlist playlist; unsigned playlist_max_length; static int playlist_stopOnError; static unsigned playlist_errorCount; -static int playlist_noGoToNext; bool playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS; @@ -594,12 +593,19 @@ enum playlist_result deleteFromPlaylist(unsigned song) /*if(playlist.current>=playlist.length) return playerStop(fd); else return playPlaylistOrderNumber(fd,playlist.current); */ playerWait(); - playlist_noGoToNext = 1; playlist.current = queue_next_order(&playlist.queue, playlist.current); if (playlist.current == (int)songOrder) playlist.current = -1; + + if (playlist.current >= 0) + /* play the song after the deleted one */ + playPlaylistOrderNumber(playlist.current); + else + /* no songs left to play, stop playback + completely */ + stopPlaylist(); } if (!song_in_database(queue_get(&playlist.queue, song))) @@ -645,7 +651,6 @@ void stopPlaylist(void) playerWait(); playlist.queued = -1; playlist.playing = false; - playlist_noGoToNext = 0; if (playlist.queue.random) { unsigned current_position = @@ -664,7 +669,6 @@ static void playPlaylistOrderNumber(int orderNum) char *uri; playlist.playing = true; - playlist_noGoToNext = 0; playlist.queued = -1; song = queue_get_order(&playlist.queue, orderNum); @@ -752,21 +756,6 @@ void syncPlayerAndPlaylist(void) } } -static void currentSongInPlaylist(void) -{ - if (!playlist.playing) - return; - - playlist_stopOnError = 0; - - syncPlaylistWithQueue(); - - if (playlist.current >= 0) - playPlaylistOrderNumber(playlist.current); - else - stopPlaylist(); -} - void nextSongInPlaylist(void) { int next_order; @@ -812,9 +801,7 @@ static void playPlaylistIfPlayerStopped(void) || error == PLAYER_ERROR_SYSTEM || playlist_errorCount >= queue_length(&playlist.queue))) { stopPlaylist(); - } else if (playlist_noGoToNext) - currentSongInPlaylist(); - else + } else nextSongInPlaylist(); } } -- cgit v1.2.3