Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playlist: fix some playlist-prev/playlist-next edge cases #14387

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion common/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void playlist_clear(struct playlist *pl)
playlist_remove(pl, pl->entries[n]);
assert(!pl->current);
pl->current_was_replaced = false;
pl->playlist_completed = false;
pl->playlist_started = false;
}

void playlist_clear_except_current(struct playlist *pl)
Expand All @@ -123,6 +125,8 @@ void playlist_clear_except_current(struct playlist *pl)
if (pl->entries[n] != pl->current)
playlist_remove(pl, pl->entries[n]);
}
pl->playlist_completed = false;
pl->playlist_started = false;
}

// Moves the entry so that it takes "at"'s place (or move to end, if at==NULL).
Expand Down Expand Up @@ -205,8 +209,13 @@ 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 && !pl->playlist_started && direction > 0) {
return playlist_entry_from_index(pl, 0);
} else if (!pl->current) {
return NULL;
}
assert(pl->current->pl == pl);
if (direction < 0)
return playlist_entry_get_rel(pl->current, -1);
Expand Down Expand Up @@ -333,6 +342,9 @@ 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;
pl->playlist_started = source_pl->playlist_started;

return first ? first->id : 0;
}

Expand Down
2 changes: 2 additions & 0 deletions common/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct playlist {
// current_was_replaced is set to true.
struct playlist_entry *current;
bool current_was_replaced;
bool playlist_completed;
bool playlist_started;

uint64_t id_alloc;
};
Expand Down
7 changes: 7 additions & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl)
struct MPOpts *opts = mpctx->opts;

pl->current = NULL;
pl->playlist_completed = false;
pl->playlist_started = false;

if (opts->playlist_pos >= 0)
pl->current = playlist_entry_from_index(pl, opts->playlist_pos);
Expand Down Expand Up @@ -1752,6 +1754,8 @@ static void play_current_file(struct MPContext *mpctx)

mpctx->playback_initialized = true;
mpctx->playing->playlist_prev_attempt = false;
mpctx->playlist->playlist_completed = false;
mpctx->playlist->playlist_started = true;
mp_notify(mpctx, MPV_EVENT_FILE_LOADED, NULL);
update_screensaver_state(mpctx);
clear_playlist_paths(mpctx);
Expand Down Expand Up @@ -1992,6 +1996,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
Loading