mpv
mpv copied to clipboard
[Windows] Accept Global Media Key Controls
How can I make mpv accept media key controls (play/pause/next/prev) globally? I did see solutions for this on mac and linux but not for windows, not anything that feels native at least.
I currently have an AutoHotKey script to do this but it has its limitations and problems.
I am fine with recompiling mpv for this
What kind of limitations and problems?
Here is another issue with AutoHotKey code example:
https://github.com/mpv-player/mpv/issues/9336
In mpv.net a global hotkey feature exist, it's based RegisterHotkey, so has limitations as well.
What kind of limitations and problems?
In AutoHotKey I am currently using ControlSend to send inputs to mpv without activating its window (similar to your script), but I am using an if statement to make sure that either mpv or the player currently active gets the play/pause instruction so for proper usability.
Relevant sections in my script:
; Play/Pause Media (mpv compatible)
!`::
IfWinNotActive, ahk_exe mpv.exe
ControlSend, ahk_parent, {Space}, ahk_exe mpv.exe
Else
SendInput, {Media_Play_Pause}
Return
; Play Next (mpv compatible)
!+n::
IfWinNotActive, ahk_exe mpv.exe
ControlSend, ahk_parent, >, ahk_exe mpv.exe
Else
SendInput, {Media_Next}
Return
; Play Previous (mpv compatible)
!+p::
IfWinNotActive, ahk_exe mpv.exe
ControlSend, ahk_parent, <, ahk_exe mpv.exe
Else
SendInput, {Media_Prev}
Return
Problems:
- This does not send input when mpv is on a different desktop than the one I am using on windows.
- Since I cannot send
Media_Play_Pauseinstructions if I ever change the bindings in mpv I will have to change it here also. - It is not a good thing for a media player to not support receiving Play/Pause instructions globally.
You can try sending commands using JSON IPC:
https://mpv.io/manual/master/#command-prompt-example
To hide the cmd window, you can use my run-hidden tool:
https://github.com/stax76/run-hidden
It's generally not a feature easy to do, on Windows there is RegisterHotkey which does not cover everything, and a powerful hook API which I would not use as it can make the system unstable when used incorrectly, additionally there is a special WM_APPCOMMAND API for media keys, it's complicated, AutoHotKey deals with all this very nicely and stable, so it's complicated, on Linux maybe even more.
So I did hear about mpv.net for windows, it seems fine but what I need is a lightweight player to play some songs while I am playing, so it needs to use as less ram as possible.
Will mpv.net be better in this case?
mpv is created with C which is more memory efficient than the C# of mpv.net. You can use the task manager if you want to see the difference.
Ok, will do. Thanks for your help
works for me after i changed mpv.exe to mpv.com
I recently noticed that the next and previous some times miss with the speed of track instead of next and previous, so i tweaked it a little bit gist link.