Skip to content

Commit

Permalink
playlist: let playlist-prev go to last item in playlist
Browse files Browse the repository at this point in the history
Previously, playlist-prev didn't work if you played a playlist to
completion using --idle and tried to go back. Naturally, one would
expect this to bring up the last item in the playlist, but nothing
happens. This is just because playlist_get_next is stupid and doesn't
take this into account since pl->current is NULL and thus returns NULL.
Fix this by considering the direction, checking if the playlist was
played to completion and grabbing the last entry in the index.
  • Loading branch information
Dudemanguy committed Jun 18, 2024
1 parent bc5ab97 commit 56fa020
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ struct playlist_entry *playlist_get_last(struct playlist *pl)
struct playlist_entry *playlist_get_next(struct playlist *pl, int direction)
{
assert(direction == -1 || direction == +1);
if (!pl->current && pl->playlist_completed && direction < 0)
return playlist_entry_from_index(pl, pl->num_entries - 1);
if (!pl->current)
return NULL;
assert(pl->current->pl == pl);
Expand Down
1 change: 1 addition & 0 deletions common/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct playlist {
// current_was_replaced is set to true.
struct playlist_entry *current;
bool current_was_replaced;
bool playlist_completed;

uint64_t id_alloc;
};
Expand Down
4 changes: 4 additions & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ static void play_current_file(struct MPContext *mpctx)

mpctx->playback_initialized = true;
mpctx->playing->playlist_prev_attempt = false;
mpctx->playlist->playlist_completed = false;
mp_notify(mpctx, MPV_EVENT_FILE_LOADED, NULL);
update_screensaver_state(mpctx);
clear_playlist_paths(mpctx);
Expand Down Expand Up @@ -1992,6 +1993,9 @@ void mp_play_files(struct MPContext *mpctx)
new_entry = mpctx->playlist->current;
}

if (!new_entry)
mpctx->playlist->playlist_completed = true;

mpctx->playlist->current = new_entry;
mpctx->playlist->current_was_replaced = false;
mpctx->stop_play = new_entry ? PT_NEXT_ENTRY : PT_STOP;
Expand Down

0 comments on commit 56fa020

Please sign in to comment.