History

common/playlist: add playlist_set_current()

Kacper Michajłow committed 2 years ago

Commit ff1f8ba1 parent 73b58723 files · +25 −14Browse files

Unified · Split

3 files
  1. common/playlist.c +21 −0
  2. common/playlist.h +2 −0
  3. player/loadfile.c +2 −14
common/playlist.c+21−0
@@ -434,3 +434,24 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel, · 433 unmodified lines
434 talloc_free(log);434 talloc_free(log);
435 return ret;435 return ret;
436}436}
437
438void playlist_set_current(struct playlist *pl)
439{
440 if (!pl->playlist_dir)
441 return;
442
443 for (int i = 0; i < pl->num_entries; ++i) {
444 if (!pl->entries[i]->playlist_path)
445 continue;
446 char *path = pl->entries[i]->playlist_path;
447 if (path[0] != '.')
448 path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path);
449 bool same = !strcmp(pl->entries[i]->filename, path);
450 if (path != pl->entries[i]->playlist_path)
451 talloc_free(path);
452 if (same) {
453 pl->current = pl->entries[i];
454 break;
455 }
456 }
457}
common/playlist.h+2−0
@@ -125,4 +125,6 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel, · 124 unmodified lines
125 125
126void playlist_entry_unref(struct playlist_entry *e);126void playlist_entry_unref(struct playlist_entry *e);
127 127
128void playlist_set_current(struct playlist *pl);
129
128#endif130#endif
player/loadfile.c+2−14
@@ -1042,20 +1042,8 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl) · 1041 unmodified lines
1042 if (opts->playlist_pos >= 0)1042 if (opts->playlist_pos >= 0)
1043 pl->current = playlist_entry_from_index(pl, opts->playlist_pos);1043 pl->current = playlist_entry_from_index(pl, opts->playlist_pos);
1044 1044
1045 for (int i = 0; i < pl->num_entries && pl->playlist_dir; ++i) {1045 if (pl->playlist_dir)
1046 if (!pl->entries[i]->playlist_path)1046 playlist_set_current(pl);
1047 continue;
1048 char *path = pl->entries[i]->playlist_path;
1049 if (path[0] != '.')
1050 path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path);
1051 bool same = !strcmp(pl->entries[i]->filename, path);
1052 if (path != pl->entries[i]->playlist_path)
1053 talloc_free(path);
1054 if (same) {
1055 pl->current = pl->entries[i];
1056 break;
1057 }
1058 }
1059 1047
1060 if (opts->shuffle)1048 if (opts->shuffle)
1061 playlist_shuffle(pl);1049 playlist_shuffle(pl);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t