Skip to content

Commit

Permalink
win32: add Media Control support
Browse files Browse the repository at this point in the history
Add support for SystemMediaTransportControls interface. This allows to
control mpv from Windows media control ui.
  • Loading branch information
kasper93 committed Jul 29, 2024
1 parent 06da680 commit 5fed12e
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 0 deletions.
1 change: 1 addition & 0 deletions DOCS/interface-changes/media-controls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--media-controls` option
7 changes: 7 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7420,6 +7420,13 @@ Miscellaneous

.. warning:: Using realtime priority can cause system lockup.

``--media-controls=<yes|player|no>``
(Windows only)
Enable integration of media control interface SystemMediaTransportControls.
If set to ``player``, only the player will use the controls. Setting it to
``yes`` will also enable the controls for libmpv integrations.
(default: ``player``)

``--force-media-title=<string>``
Force the contents of the ``media-title`` property to this value. Useful
for scripts which want to set a title, without overriding the user's
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ if not posix and not features['win32-desktop']
'osdep/terminal-dummy.c')
endif

if win32
subdir('osdep/win32')
endif

features += {'glob-posix': cc.has_function('glob', prefix: '#include <glob.h>')}

features += {'glob-win32': win32 and not features['glob-posix']}
Expand Down
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ option('macos-touchbar', type: 'feature', value: 'auto', description: 'macOS Tou
option('swift-build', type: 'feature', value: 'auto', description: 'macOS Swift build tools')
option('swift-flags', type: 'string', description: 'Optional Swift compiler flags')

# Windows features
option('win32-smtc', type: 'feature', value: 'auto', description: 'Enable Media Control support')

# manpages
option('html-build', type: 'feature', value: 'disabled', description: 'HTML manual generation')
option('manpage-build', type: 'feature', value: 'auto', description: 'manpage generation')
Expand Down
2 changes: 2 additions & 0 deletions misc/path_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ char *mp_getcwd(void *talloc_ctx)

char *mp_normalize_path(void *talloc_ctx, const char *path)
{
assert(talloc_ctx && "mp_normalize_path requires talloc_ctx!");

if (!path)
return NULL;

Expand Down
3 changes: 3 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ static const m_option_t mp_opts[] = {
{"idle", IDLE_PRIORITY_CLASS}),
.flags = UPDATE_PRIORITY},
#endif
{"media-controls", OPT_CHOICE(media_controls,
{"no", 0}, {"player", 1}, {"yes", 2})},
{"config", OPT_BOOL(load_config), .flags = CONF_PRE_PARSE},
{"config-dir", OPT_STRING(force_configdir),
.flags = CONF_NOCFG | CONF_PRE_PARSE | M_OPT_FILE},
Expand Down Expand Up @@ -1039,6 +1041,7 @@ static const struct MPOpts mp_default_opts = {
.osd_bar_visible = true,
.screenshot_template = "mpv-shot%n",
.play_dir = 1,
.media_controls = 1,

.audiofile_auto_exts = (char *[]){
"aac",
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ typedef struct MPOpts {
bool osd_bar_visible;

int w32_priority;
int media_controls;

struct bluray_opts *stream_bluray_opts;
struct cdda_opts *stream_cdda_opts;
Expand Down
8 changes: 8 additions & 0 deletions osdep/win32/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_languages('cpp', native: false)
cpp = meson.get_compiler('cpp')

features += {'win32-smtc': cpp.has_header('winrt/base.h', required: get_option('win32-smtc'))}
if features['win32-smtc']
dependencies += cpp.find_library('runtimeobject')
sources += meson.current_source_dir() / 'smtc.cpp'
endif
Loading

0 comments on commit 5fed12e

Please sign in to comment.