summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-21 17:45:30 +0100
committerwm4 <wm4@nowhere>2020-03-21 19:33:03 +0100
commit7e885a3bc3af4df93681b6e760a34e59e2f47ef7 (patch)
treec2687c6b364a2e5aeef0c466fb04988bafc35ab3 /player
parent956a5d9ac61ffe4034abcc81405e8ecdacac8b36 (diff)
downloadmpv-7e885a3bc3af4df93681b6e760a34e59e2f47ef7.tar.bz2
mpv-7e885a3bc3af4df93681b6e760a34e59e2f47ef7.tar.xz
client API: add a playlist entry unique ID
This should make dealing with some async. things easier. It's intentionally not a globally unique ID.
Diffstat (limited to 'player')
-rw-r--r--player/command.c14
-rw-r--r--player/loadfile.c10
2 files changed, 22 insertions, 2 deletions
diff --git a/player/command.c b/player/command.c
index f8e248880a..e567ffb032 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2798,6 +2798,7 @@ static int get_playlist_entry(int item, int action, void *arg, void *ctx)
{"current", SUB_PROP_FLAG(1), .unavailable = !current},
{"playing", SUB_PROP_FLAG(1), .unavailable = !playing},
{"title", SUB_PROP_STR(e->title), .unavailable = !e->title},
+ {"id", SUB_PROP_INT64(e->id)},
{0}
};
@@ -4881,6 +4882,10 @@ static void cmd_loadfile(void *p)
}
playlist_add(mpctx->playlist, entry);
+ struct mpv_node *res = &cmd->result;
+ node_init(res, MPV_FORMAT_NODE_MAP, NULL);
+ node_map_add_int64(res, "playlist_entry_id", entry->id);
+
if (!append || (append == 2 && !mpctx->playlist->current)) {
if (mpctx->opts->position_save_on_quit) // requested in issue #1148
mp_write_watch_later_conf(mpctx);
@@ -4904,6 +4909,8 @@ static void cmd_loadlist(void *p)
struct playlist_entry *new = pl->current;
if (!append)
playlist_clear(mpctx->playlist);
+ struct playlist_entry *first = playlist_entry_from_index(pl, 0);
+ int num_entries = pl->num_entries;
playlist_append_entries(mpctx->playlist, pl);
talloc_free(pl);
@@ -4913,6 +4920,13 @@ static void cmd_loadlist(void *p)
if (!append && new)
mp_set_playlist_entry(mpctx, new);
+ struct mpv_node *res = &cmd->result;
+ node_init(res, MPV_FORMAT_NODE_MAP, NULL);
+ if (num_entries) {
+ node_map_add_int64(res, "playlist_entry_id", first->id);
+ node_map_add_int64(res, "num_entries", num_entries);
+ }
+
mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL);
mp_wakeup_core(mpctx);
} else {
diff --git a/player/loadfile.c b/player/loadfile.c
index 4d16a66376..46627a9b23 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1381,7 +1381,11 @@ static void play_current_file(struct MPContext *mpctx)
if (mpctx->stop_play || !mpctx->playlist->current)
return;
- mp_notify(mpctx, MPV_EVENT_START_FILE, NULL);
+ mpv_event_start_file start_event = {
+ .playlist_entry_id = mpctx->playlist->current->id,
+ };
+
+ mp_notify(mpctx, MPV_EVENT_START_FILE, &start_event);
mp_cancel_reset(mpctx->playback_abort);
@@ -1653,7 +1657,9 @@ terminate_playback:
bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes &&
mpctx->error_playing <= 0;
- struct mpv_event_end_file end_event = {0};
+ struct mpv_event_end_file end_event = {
+ .playlist_entry_id = start_event.playlist_entry_id,
+ };
switch (mpctx->stop_play) {
case PT_ERROR:
case AT_END_OF_FILE: