mirror of https://github.com/mpv-player/mpv
common/playlist: add playlist_set_current()
This commit is contained in:
parent
73b58722e7
commit
ff1f8baecd
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue