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

common/playlist: add playlist_set_current()

This commit is contained in:
Kacper Michajłow 2024-07-29 21:10:44 +02:00
parent 73b58722e7
commit ff1f8baecd
3 changed files with 25 additions and 14 deletions

View File

@ -434,3 +434,24 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel,
talloc_free(log);
return ret;
}
void playlist_set_current(struct playlist *pl)
{
if (!pl->playlist_dir)
return;
for (int i = 0; i < pl->num_entries; ++i) {
if (!pl->entries[i]->playlist_path)
continue;
char *path = pl->entries[i]->playlist_path;
if (path[0] != '.')
path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path);
bool same = !strcmp(pl->entries[i]->filename, path);
if (path != pl->entries[i]->playlist_path)
talloc_free(path);
if (same) {
pl->current = pl->entries[i];
break;
}
}
}

View File

@ -125,4 +125,6 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel,
void playlist_entry_unref(struct playlist_entry *e);
void playlist_set_current(struct playlist *pl);
#endif

View File

@ -1042,20 +1042,8 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl)
if (opts->playlist_pos >= 0)
pl->current = playlist_entry_from_index(pl, opts->playlist_pos);
for (int i = 0; i < pl->num_entries && pl->playlist_dir; ++i) {
if (!pl->entries[i]->playlist_path)
continue;
char *path = pl->entries[i]->playlist_path;
if (path[0] != '.')
path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path);
bool same = !strcmp(pl->entries[i]->filename, path);
if (path != pl->entries[i]->playlist_path)
talloc_free(path);
if (same) {
pl->current = pl->entries[i];
break;
}
}
if (pl->playlist_dir)
playlist_set_current(pl);
if (opts->shuffle)
playlist_shuffle(pl);