mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
player: allow overriding OSD message for all OSD levels
Until now, you could override only level 3 with --osd-status-msg. Extend this, add add --osd-msg1 to --osd-msg3 (one for each OSD level). OSD level 0 always means disable OSD, so that isn't included. --osd-msg3 corresponds to --osd-status-msg, but they're not exactly the same. To allow more customization, --osd-msgN do not include the OSD symbol. The symbol can be manually added with "${osd-sym-cc}". We keep the "old" option for some short-term compatibility. --osd-msg1 should be particularly useful; for example you could do: --osd-msg1='${?pause==yes:${osd-sym-cc}}' to display a "paused" symbol when paused, and nothing during normal playback. (Although admittedly, the syntax is quite a bit of work.)
This commit is contained in:
parent
6c3d25e6f5
commit
ea2b19f646
@ -2197,6 +2197,26 @@ OSD
|
||||
|
||||
Default: 45.
|
||||
|
||||
``--osd-msg1=<string>``
|
||||
Show this string as message on OSD with OSD level 1 (visible by default).
|
||||
The message will be visible by default, and as long no other message
|
||||
covers it, and the OSD level isn't changed (see ``--osd-level``).
|
||||
Expands properties; see `Property Expansion`_.
|
||||
|
||||
``--osd-msg2=<string>``
|
||||
Similar as ``--osd-msg1``, but for OSD level 2. If this is an empty string
|
||||
(default), then the playback time is shown.
|
||||
|
||||
``--osd-msg3=<string>``
|
||||
Similar as ``--osd-msg1``, but for OSD level 3. If this is an empty string
|
||||
(default), then the playback time, duration, and some more information is
|
||||
shown.
|
||||
|
||||
This is also used for the ``show_progress`` command (by default mapped to
|
||||
``P``), or in some non-default cases when seeking.
|
||||
|
||||
``--osd-status-msg`` is a legacy equivalent (but with a minor difference).
|
||||
|
||||
``--osd-status-msg=<string>``
|
||||
Show a custom string during playback instead of the standard status text.
|
||||
This overrides the status text used for ``--osd-level=3``, when using the
|
||||
@ -2204,6 +2224,10 @@ OSD
|
||||
non-default cases when seeking. Expands properties. See
|
||||
`Property Expansion`_.
|
||||
|
||||
This option has been replaced with ``--osd-msg3``. The only difference is
|
||||
that this option implicitly includes ``${osd-sym-cc}``. This option is
|
||||
ignored if ``--osd-msg3`` is not empty.
|
||||
|
||||
``--osd-playing-msg=<string>``
|
||||
Show a message on OSD when playback starts. The string is expanded for
|
||||
properties, e.g. ``--osd-playing-msg='file: ${filename}'`` will show the
|
||||
|
@ -521,6 +521,9 @@ const m_option_t mp_opts[] = {
|
||||
OPT_STRING("osd-playing-msg", osd_playing_msg, 0),
|
||||
OPT_STRING("term-status-msg", status_msg, 0),
|
||||
OPT_STRING("osd-status-msg", osd_status_msg, 0),
|
||||
OPT_STRING("osd-msg1", osd_msg[0], 0),
|
||||
OPT_STRING("osd-msg2", osd_msg[1], 0),
|
||||
OPT_STRING("osd-msg3", osd_msg[2], 0),
|
||||
|
||||
OPT_FLAG("idle", player_idle_mode, M_OPT_GLOBAL),
|
||||
OPT_FLAG("input-terminal", consolecontrols, CONF_GLOBAL),
|
||||
|
@ -148,6 +148,7 @@ typedef struct MPOpts {
|
||||
char *osd_playing_msg;
|
||||
char *status_msg;
|
||||
char *osd_status_msg;
|
||||
char *osd_msg[3];
|
||||
char *heartbeat_cmd;
|
||||
float heartbeat_interval;
|
||||
int player_idle_mode;
|
||||
|
43
player/osd.c
43
player/osd.c
@ -458,23 +458,34 @@ void get_current_osd_sym(struct MPContext *mpctx, char *buf, size_t buf_size)
|
||||
osd_get_function_sym(buf, buf_size, sym);
|
||||
}
|
||||
|
||||
static void sadd_osd_status(char **buffer, struct MPContext *mpctx, bool full)
|
||||
static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level)
|
||||
{
|
||||
bool fractions = mpctx->opts->osd_fractions;
|
||||
char sym[10];
|
||||
get_current_osd_sym(mpctx, sym, sizeof(sym));
|
||||
saddf(buffer, "%s ", sym);
|
||||
char *custom_msg = mpctx->opts->osd_status_msg;
|
||||
if (custom_msg && full) {
|
||||
char *text = mp_property_expand_escaped_string(mpctx, custom_msg);
|
||||
assert(level >= 0 && level <= 3);
|
||||
if (level == 0)
|
||||
return;
|
||||
char *msg = mpctx->opts->osd_msg[level - 1];
|
||||
|
||||
if (msg && msg[0]) {
|
||||
char *text = mp_property_expand_escaped_string(mpctx, msg);
|
||||
*buffer = talloc_strdup_append(*buffer, text);
|
||||
talloc_free(text);
|
||||
} else {
|
||||
sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
|
||||
if (full) {
|
||||
saddf(buffer, " / ");
|
||||
sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);
|
||||
sadd_percentage(buffer, get_percent_pos(mpctx));
|
||||
} else if (level >= 2) {
|
||||
bool fractions = mpctx->opts->osd_fractions;
|
||||
char sym[10];
|
||||
get_current_osd_sym(mpctx, sym, sizeof(sym));
|
||||
saddf(buffer, "%s ", sym);
|
||||
char *custom_msg = mpctx->opts->osd_status_msg;
|
||||
if (custom_msg && level == 3) {
|
||||
char *text = mp_property_expand_escaped_string(mpctx, custom_msg);
|
||||
*buffer = talloc_strdup_append(*buffer, text);
|
||||
talloc_free(text);
|
||||
} else {
|
||||
sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
|
||||
if (level == 3) {
|
||||
saddf(buffer, " / ");
|
||||
sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);
|
||||
sadd_percentage(buffer, get_percent_pos(mpctx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -547,9 +558,7 @@ void update_osd_msg(struct MPContext *mpctx)
|
||||
|
||||
// clear, or if OSD level demands it, show the status
|
||||
char *text = NULL;
|
||||
|
||||
if (osd_level >= 2)
|
||||
sadd_osd_status(&text, mpctx, osd_level == 3);
|
||||
sadd_osd_status(&text, mpctx, osd_level);
|
||||
|
||||
osd_set_text(osd, OSDTYPE_OSD, text);
|
||||
talloc_free(text);
|
||||
|
Loading…
Reference in New Issue
Block a user