0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-19 19:42:24 +02:00

playlist: let playlist-prev go to last item in playlist

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.
This commit is contained in:
Dudemanguy 2024-06-18 17:55:03 -05:00
parent 111571bd05
commit 0f76848e5f
3 changed files with 14 additions and 1 deletions

View File

@ -115,6 +115,7 @@ void playlist_clear(struct playlist *pl)
playlist_remove(pl, pl->entries[n]);
assert(!pl->current);
pl->current_was_replaced = false;
pl->playlist_completed = false;
}
void playlist_clear_except_current(struct playlist *pl)
@ -123,6 +124,7 @@ void playlist_clear_except_current(struct playlist *pl)
if (pl->entries[n] != pl->current)
playlist_remove(pl, pl->entries[n]);
}
pl->playlist_completed = false;
}
// Moves the entry so that it takes "at"'s place (or move to end, if at==NULL).
@ -205,8 +207,11 @@ 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)
if (!pl->current && pl->playlist_completed && direction < 0) {
return playlist_entry_from_index(pl, pl->num_entries - 1);
} else if (!pl->current) {
return NULL;
}
assert(pl->current->pl == pl);
if (direction < 0)
return playlist_entry_get_rel(pl->current, -1);
@ -333,6 +338,8 @@ int64_t playlist_transfer_entries_to(struct playlist *pl, int dst_index,
playlist_update_indexes(pl, dst_index + count, -1);
source_pl->num_entries = 0;
pl->playlist_completed = source_pl->playlist_completed;
return first ? first->id : 0;
}

View File

@ -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;
};

View File

@ -1032,6 +1032,7 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl)
struct MPOpts *opts = mpctx->opts;
pl->current = NULL;
pl->playlist_completed = false;
if (opts->playlist_pos >= 0)
pl->current = playlist_entry_from_index(pl, opts->playlist_pos);
@ -1760,6 +1761,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);
@ -2000,6 +2002,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;