mirror of
https://github.com/mpv-player/mpv
synced 2025-01-02 21:12:23 +00:00
client API: add chapter change event
Also works for mpv_observe_property() on the "chapter" property.
This commit is contained in:
parent
b20416abe3
commit
e8a996cede
@ -533,3 +533,6 @@ List of events
|
|||||||
|
|
||||||
``metadata-update``
|
``metadata-update``
|
||||||
Metadata (like file tags) was updated.
|
Metadata (like file tags) was updated.
|
||||||
|
|
||||||
|
``chapter-change``
|
||||||
|
The current chapter possibly changed.
|
||||||
|
@ -913,7 +913,11 @@ typedef enum mpv_event_id {
|
|||||||
* Event sent due to mpv_observe_property().
|
* Event sent due to mpv_observe_property().
|
||||||
* See also mpv_event and mpv_event_property.
|
* See also mpv_event and mpv_event_property.
|
||||||
*/
|
*/
|
||||||
MPV_EVENT_PROPERTY_CHANGE = 22
|
MPV_EVENT_PROPERTY_CHANGE = 22,
|
||||||
|
/**
|
||||||
|
* Happens when the current chapter changes.
|
||||||
|
*/
|
||||||
|
MPV_EVENT_CHAPTER_CHANGE = 23
|
||||||
} mpv_event_id;
|
} mpv_event_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1317,6 +1317,7 @@ static const char *event_table[] = {
|
|||||||
[MPV_EVENT_SEEK] = "seek",
|
[MPV_EVENT_SEEK] = "seek",
|
||||||
[MPV_EVENT_PLAYBACK_RESTART] = "playback-restart",
|
[MPV_EVENT_PLAYBACK_RESTART] = "playback-restart",
|
||||||
[MPV_EVENT_PROPERTY_CHANGE] = "property-change",
|
[MPV_EVENT_PROPERTY_CHANGE] = "property-change",
|
||||||
|
[MPV_EVENT_CHAPTER_CHANGE] = "chapter-change",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *mpv_event_name(mpv_event_id event)
|
const char *mpv_event_name(mpv_event_id event)
|
||||||
|
@ -2443,6 +2443,7 @@ const char **mp_event_property_change[] = {
|
|||||||
E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate",
|
E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate",
|
||||||
"samplerate", "channels", "audio"),
|
"samplerate", "channels", "audio"),
|
||||||
E(MPV_EVENT_METADATA_UPDATE, "metadata"),
|
E(MPV_EVENT_METADATA_UPDATE, "metadata"),
|
||||||
|
E(MPV_EVENT_CHAPTER_CHANGE, "chapter", "chapter-metadata"),
|
||||||
};
|
};
|
||||||
#undef E
|
#undef E
|
||||||
|
|
||||||
|
@ -276,6 +276,8 @@ typedef struct MPContext {
|
|||||||
// Video PTS, or audio PTS if video has ended.
|
// Video PTS, or audio PTS if video has ended.
|
||||||
double playback_pts;
|
double playback_pts;
|
||||||
|
|
||||||
|
int last_chapter;
|
||||||
|
|
||||||
// History of video frames timestamps that were queued in the VO
|
// History of video frames timestamps that were queued in the VO
|
||||||
// This includes even skipped frames during hr-seek
|
// This includes even skipped frames during hr-seek
|
||||||
double vo_pts_history_pts[MAX_NUM_VO_PTS];
|
double vo_pts_history_pts[MAX_NUM_VO_PTS];
|
||||||
|
@ -1333,6 +1333,7 @@ goto_reopen_demuxer: ;
|
|||||||
mpctx->paused = false;
|
mpctx->paused = false;
|
||||||
mpctx->paused_for_cache = false;
|
mpctx->paused_for_cache = false;
|
||||||
mpctx->eof_reached = false;
|
mpctx->eof_reached = false;
|
||||||
|
mpctx->last_chapter = -2;
|
||||||
mpctx->seek = (struct seek_params){ 0 };
|
mpctx->seek = (struct seek_params){ 0 };
|
||||||
|
|
||||||
// If there's a timeline force an absolute seek to initialize state
|
// If there's a timeline force an absolute seek to initialize state
|
||||||
|
@ -310,6 +310,7 @@ struct MPContext *mp_create(void)
|
|||||||
struct MPContext *mpctx = talloc(NULL, MPContext);
|
struct MPContext *mpctx = talloc(NULL, MPContext);
|
||||||
*mpctx = (struct MPContext){
|
*mpctx = (struct MPContext){
|
||||||
.last_dvb_step = 1,
|
.last_dvb_step = 1,
|
||||||
|
.last_chapter = -2,
|
||||||
.term_osd_contents = talloc_strdup(mpctx, ""),
|
.term_osd_contents = talloc_strdup(mpctx, ""),
|
||||||
.osd_progbar = { .type = -1 },
|
.osd_progbar = { .type = -1 },
|
||||||
.playlist = talloc_struct(mpctx, struct playlist, {0}),
|
.playlist = talloc_struct(mpctx, struct playlist, {0}),
|
||||||
|
@ -845,6 +845,15 @@ static void handle_keep_open(struct MPContext *mpctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handle_chapter_change(struct MPContext *mpctx)
|
||||||
|
{
|
||||||
|
int chapter = get_current_chapter(mpctx);
|
||||||
|
if (chapter != mpctx->last_chapter) {
|
||||||
|
mpctx->last_chapter = chapter;
|
||||||
|
mp_notify(mpctx, MPV_EVENT_CHAPTER_CHANGE, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute a forceful refresh of the VO window, if it hasn't had a valid frame
|
// Execute a forceful refresh of the VO window, if it hasn't had a valid frame
|
||||||
// for a while. The problem is that a VO with no valid frame (vo->hasframe==0)
|
// for a while. The problem is that a VO with no valid frame (vo->hasframe==0)
|
||||||
// doesn't redraw video and doesn't OSD interaction. So screw it, hard.
|
// doesn't redraw video and doesn't OSD interaction. So screw it, hard.
|
||||||
@ -1295,6 +1304,8 @@ void run_playloop(struct MPContext *mpctx)
|
|||||||
|
|
||||||
handle_keep_open(mpctx);
|
handle_keep_open(mpctx);
|
||||||
|
|
||||||
|
handle_chapter_change(mpctx);
|
||||||
|
|
||||||
handle_force_window(mpctx, false);
|
handle_force_window(mpctx, false);
|
||||||
|
|
||||||
execute_queued_seek(mpctx);
|
execute_queued_seek(mpctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user