love2d / love-android

Android build setup for LÖVE.
https://love2d.org
Other
200 stars 70 forks source link

Catching volume buttons #236

Closed ravener closed 2 years ago

ravener commented 2 years ago

Is there a way to handle volume buttons?

I previously used libGDX which allowed something like:

Gdx.input.setCatchKey(Keys.VOLUME_DOWN, true);

Then I can handle volume button presses like any other key.

It wasn't mentioned in the keyboard wiki so I'm wondering if it's already possible or if not, consider it a suggestion.

slime73 commented 2 years ago

There are "volumeup" and "volumedown" scancodes you could try https://love2d.org/wiki/Scancode#Media_scancodes (via love.keypressed or love.keyboard.isScancodeDown). I'm not sure whether SDL's android backend has those hooked up or not.

ravener commented 2 years ago

Yeah they don't work as is, I'm sure there must be some Android related thing to be done first because the system handles it to control the sound.

MikuAuahDark commented 2 years ago

SDL intentionally doesn't support this feature. https://github.com/libsdl-org/SDL/blob/8c9beb0c873f6ca5efbd88f1ad2648bfc793b2ac/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java#L645-L662

It may be worth asking to support this use case in SDL though, probably as runtime hints that can be set.