Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media control Shortcuts #1824

Open
MonDV opened this issue Oct 10, 2020 · 9 comments
Open

Media control Shortcuts #1824

MonDV opened this issue Oct 10, 2020 · 9 comments

Comments

@MonDV
Copy link

MonDV commented Oct 10, 2020

I have been using vysor to control my FireTV devices and since they upgraded to v3 it's been a complete cluster****. Found your tool yesterday and it does 99% of everything I need and it is GREAT!

There is one issue/request. Can you add media control shortcuts? Specifically to rewind, play/pause, forward media. For the FireTV the keycodes are:

KEYCODE_MEDIA_PLAY_PAUSE
KEYCODE_MEDIA_REWIND
KEYCODE_MEDIA_FAST_FORWARD

In vysor, I modify the settings so that my current laptop buttons for these 'functions' is linked to the keycode (currently F9, F10 and F11 buttons).

It would be great to add shortcuts that would pass those keycodes so that it is possible to control media play through scrcpy.

FYI, I am not a programmer and I don't know the complexity of this request. Best, MonDV (Thanks for the great tool!!!)

@rom1v
Copy link
Collaborator

rom1v commented Nov 9, 2020

Just to test, this works:

diff --git a/app/src/event_converter.c b/app/src/event_converter.c
index ab48898d..dc88c239 100644
--- a/app/src/event_converter.c
+++ b/app/src/event_converter.c
@@ -96,6 +96,9 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod,
         MAP(SDLK_RCTRL,        AKEYCODE_CTRL_RIGHT);
         MAP(SDLK_LSHIFT,       AKEYCODE_SHIFT_LEFT);
         MAP(SDLK_RSHIFT,       AKEYCODE_SHIFT_RIGHT);
+        MAP(SDLK_F9,           AKEYCODE_MEDIA_PLAY_PAUSE);
+        MAP(SDLK_F10,          AKEYCODE_MEDIA_REWIND);
+        MAP(SDLK_F11,          AKEYCODE_MEDIA_FAST_FORWARD);
     }
 
     if (!(mod & (KMOD_NUM | KMOD_SHIFT))) {

But there is no customizable mapping on scrcpy (and media keys are not correctly received by SDL, for example I never receive SDLK_AUDIOPLAY if I click on my mediakey PLAY).

@hafizidev
Copy link

Just to test, this works:

diff --git a/app/src/event_converter.c b/app/src/event_converter.c
index ab48898d..dc88c239 100644
--- a/app/src/event_converter.c
+++ b/app/src/event_converter.c
@@ -96,6 +96,9 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod,
         MAP(SDLK_RCTRL,        AKEYCODE_CTRL_RIGHT);
         MAP(SDLK_LSHIFT,       AKEYCODE_SHIFT_LEFT);
         MAP(SDLK_RSHIFT,       AKEYCODE_SHIFT_RIGHT);
+        MAP(SDLK_F9,           AKEYCODE_MEDIA_PLAY_PAUSE);
+        MAP(SDLK_F10,          AKEYCODE_MEDIA_REWIND);
+        MAP(SDLK_F11,          AKEYCODE_MEDIA_FAST_FORWARD);
     }
 
     if (!(mod & (KMOD_NUM | KMOD_SHIFT))) {

But there is no customizable mapping on scrcpy (and media keys are not correctly received by SDL, for example I never receive SDLK_AUDIOPLAY if I click on my mediakey PLAY).

How to use this ? click on F9, F10 and f11 ? Doesn't seems to works for me.
But I'm on MI9T's Android 10 MIUI, is it the reason why it doesn't work

@rom1v
Copy link
Collaborator

rom1v commented Apr 16, 2021

Does it work for you:

adb shell input keyevent MEDIA_PLAY_PAUSE

?

On some laptops, Fn is "enabled" by default (customizable from BIOS/UEFI), so you need to press Fn+F9.

@hafizidev
Copy link

adb shell input keyevent MEDIA_PLAY_PAUSE

Running this works for me. Music paused and played

And I disabled Fn a while back on my laptop, as I am using F2 very frequently for renaming, so this is not the problem for me I

@rom1v
Copy link
Collaborator

rom1v commented Apr 16, 2021

@hafizidev How did you compiled scrcpy including this patch?

@hafizidev
Copy link

@hafizidev How did you compiled scrcpy including this patch?

I am very sorry, I didn't notice that this is development feature. I use the release version, not development, no wonder it didn't work. Sorry again

@samxkevin
Copy link

Does it work for you:

adb shell input keyevent MEDIA_PLAY_PAUSE

?

On some laptops, Fn is "enabled" by default (customizable from BIOS/UEFI), so you need to press Fn+F9.

What about next track or previous track

@Sledmine
Copy link

Sledmine commented Apr 5, 2024

Does it work for you:

adb shell input keyevent MEDIA_PLAY_PAUSE

?
On some laptops, Fn is "enabled" by default (customizable from BIOS/UEFI), so you need to press Fn+F9.

What about next track or previous track

Checkout Android Key Events docs:
https://developer.android.com/reference/android/view/KeyEvent

@Gottox
Copy link
Contributor

Gottox commented Jun 12, 2024

maybe related: #4080

Background, why this might be not enough on linux systems: On most Desktop environments, the wayland shell/Xwindow manager will receive these button events and handle them theirselves. For sharing actions with the actual applications, so that they can respond to these actions, these applications implement dbus MPRIS. I'm currently looking at an implementation for mpv which looks quite minimal (as minimal as it gets with dbus...) to maybe port this over to scrcpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants