mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.25k stars 2.9k forks source link

is it possible to add a key binding using the client API? #6778

Closed stax76 closed 5 years ago

stax76 commented 5 years ago

Hello,

there is a user of mpv.net who wants to add a key binding with dotnet using the client API. I tried to achieve this and think it's only possible by generating and running JavaScript code and then communicate between JavaScript and dotnet via script-message command and client-message event, is there not an easier way?

avih commented 5 years ago

"easier" is relative. The lua and js code for key binding don't do any magic, they simply define the mp.add_key_binding functions as wrapper around other mpv commands, and use script messages to handle the callbacks. E.g. the JS binding is: https://github.com/mpv-player/mpv/blob/master/player/javascript/defaults.js#L141

Whether or not it's easier for you to utilize existing lua/js code and interface it to your dotnet thingy, or duplicate the wrapper yourself in dotnet - is up to you.

stax76 commented 5 years ago

In defaults.js I found the commands define-section and enable-section, that looks promising, thanks.

stax76 commented 5 years ago

Works great, thanks again!

avih commented 5 years ago

You're welcome.

Note that the define-section interface is subject to change: https://mpv.io/manual/master/#input-commands-that-are-possibly-subject-to-change , so if it does, your code might break (and similarly, the internal lua and js key bindings code would need to change as well).

stax76 commented 5 years ago

Do you know why it might change?

avih commented 5 years ago

No, but I guess that whoever wrote it thought that it's not the cleanest interface and that in the future it could be replaced by something else. But that's a guess.

Akemi commented 5 years ago

i guess that was resolved.