summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmpv/client.h14
-rw-r--r--player/client.c3
-rw-r--r--player/loadfile.c13
3 files changed, 29 insertions, 1 deletions
diff --git a/libmpv/client.h b/libmpv/client.h
index d417d8bbdb..375b440dce 100644
--- a/libmpv/client.h
+++ b/libmpv/client.h
@@ -817,6 +817,7 @@ typedef enum mpv_event_id {
MPV_EVENT_START_FILE = 6,
/**
* Notification after playback end (after the file was unloaded).
+ * See also mpv_event and mpv_event_end_file.
*/
MPV_EVENT_END_FILE = 7,
/**
@@ -1000,6 +1001,18 @@ typedef struct mpv_event_pause_reason {
int by_keep_open;
} mpv_event_pause_reason;
+typedef struct mpv_event_end_file {
+ /**
+ * Identifies the reason why playback was stopped:
+ * 0: the end of the file was reached or initialization failed
+ * 1: the file is restarted (e.g. edition switching)
+ * 2: playback was aborted by an external action (e.g. playlist controls)
+ * 3: the player received the quit command
+ * Other values should be treated as unknown.
+ */
+ int reason;
+} mpv_event_end_file;
+
typedef struct mpv_event_script_input_dispatch {
/**
* Arbitrary integer value that was provided as argument to the
@@ -1054,6 +1067,7 @@ typedef struct mpv_event {
* MPV_EVENT_UNPAUSE: mpv_event_pause_reason*
* MPV_EVENT_SCRIPT_INPUT_DISPATCH: mpv_event_script_input_dispatch*
* MPV_EVENT_CLIENT_MESSAGE: mpv_event_client_message*
+ * MPV_EVENT_END_FILE: mpv_event_end_file*
* other: NULL
*
* Note: future enhancements might add new event structs for existing or new
diff --git a/player/client.c b/player/client.c
index 2347f19fbd..642937421d 100644
--- a/player/client.c
+++ b/player/client.c
@@ -393,6 +393,9 @@ static void dup_event_data(struct mpv_event *ev)
ev->data = msg;
break;
}
+ case MPV_EVENT_END_FILE:
+ ev->data = talloc_memdup(NULL, ev->data, sizeof(mpv_event_end_file));
+ break;
default:
// Doesn't use events with memory allocation.
if (ev->data)
diff --git a/player/loadfile.c b/player/loadfile.c
index 95cc871e42..ee3deed4a8 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1421,7 +1421,18 @@ terminate_playback: // don't jump here after ao/vo/getch initialization!
}
mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL);
- mp_notify(mpctx, MPV_EVENT_END_FILE, NULL);
+ struct mpv_event_end_file end_event = {0};
+ switch (mpctx->stop_play) {
+ case AT_END_OF_FILE: end_event.reason = 0; break;
+ case PT_RESTART:
+ case PT_RELOAD_DEMUXER: end_event.reason = 1; break;
+ case PT_NEXT_ENTRY:
+ case PT_CURRENT_ENTRY:
+ case PT_STOP: end_event.reason = 2; break;
+ case PT_QUIT: end_event.reason = 3; break;
+ default: end_event.reason = -1; break;
+ };
+ mp_notify(mpctx, MPV_EVENT_END_FILE, &end_event);
}
// Determine the next file to play. Note that if this function returns non-NULL,