mirror of
https://github.com/mpv-player/mpv
synced 2025-03-03 04:37:54 +00:00
commands: add show_chapters_osd command to display chapters on OSD
The command lists the chapters in the current file on the OSD. It also marks the current chapter. This is actually a cheap replacement for the chapter select libmenu functionality.
This commit is contained in:
parent
ac771d288d
commit
af7a29424c
@ -493,6 +493,8 @@ vo_rootwin [value]
|
||||
volume <value> [abs]
|
||||
Increase/decrease volume or set it to <value> if [abs] is nonzero.
|
||||
|
||||
show_chapters_osd
|
||||
Show the list of chapters in the currently played file on the OSD.
|
||||
|
||||
Available properties:
|
||||
|
||||
|
41
command.c
41
command.c
@ -2806,6 +2806,44 @@ static void clear_play_tree(MPContext *mpctx)
|
||||
do_clear_pt(mpctx->playtree, exclude);
|
||||
}
|
||||
|
||||
static char *format_time(double time)
|
||||
{
|
||||
int h, m, s = time;
|
||||
h = s / 3600;
|
||||
s -= h * 3600;
|
||||
m = s / 60;
|
||||
s -= m * 60;
|
||||
return talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
|
||||
}
|
||||
|
||||
static void show_chapters_on_osd(MPContext *mpctx)
|
||||
{
|
||||
int count = get_chapter_count(mpctx);
|
||||
int cur = mpctx->demuxer ? get_current_chapter(mpctx) : -1;
|
||||
char *res = NULL;
|
||||
int n;
|
||||
|
||||
if (count < 1) {
|
||||
res = talloc_asprintf_append(res, "No chapters.");
|
||||
}
|
||||
|
||||
for (n = 0; n < count; n++) {
|
||||
char *name = chapter_display_name(mpctx, n);
|
||||
double t = chapter_start_time(mpctx, n);
|
||||
char* time = format_time(t);
|
||||
res = talloc_asprintf_append(res, "%s", time);
|
||||
talloc_free(time);
|
||||
char *m1 = "> ", *m2 = " <";
|
||||
if (n != cur)
|
||||
m1 = m2 = "";
|
||||
res = talloc_asprintf_append(res, " %s%s%s\n", m1, name, m2);
|
||||
talloc_free(name);
|
||||
}
|
||||
|
||||
set_osd_msg(OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", res);
|
||||
talloc_free(res);
|
||||
}
|
||||
|
||||
void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
{
|
||||
struct MPOpts *opts = &mpctx->opts;
|
||||
@ -3622,6 +3660,9 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
af_reinit(sh_audio->afilter, af);
|
||||
}
|
||||
break;
|
||||
case MP_CMD_SHOW_CHAPTERS:
|
||||
show_chapters_on_osd(mpctx);
|
||||
break;
|
||||
|
||||
default:
|
||||
mp_msg(MSGT_CPLAYER, MSGL_V,
|
||||
|
@ -221,6 +221,9 @@ static const mp_cmd_t mp_cmds[] = {
|
||||
{ MP_CMD_AF_DEL, "af_del", { ARG_STRING } },
|
||||
{ MP_CMD_AF_CLR, "af_clr", },
|
||||
{ MP_CMD_AF_CMDLINE, "af_cmdline", { ARG_STRING, ARG_STRING } },
|
||||
|
||||
{ MP_CMD_SHOW_CHAPTERS, "show_chapters_osd", },
|
||||
|
||||
{0}
|
||||
};
|
||||
|
||||
|
@ -153,6 +153,8 @@ enum mp_command_type {
|
||||
MP_CMD_AF_DEL,
|
||||
MP_CMD_AF_CLR,
|
||||
MP_CMD_AF_CMDLINE,
|
||||
|
||||
MP_CMD_SHOW_CHAPTERS,
|
||||
};
|
||||
|
||||
// The arg types
|
||||
|
Loading…
Reference in New Issue
Block a user