a-dekker / smpc

Official port of Qt/Qml based qmobilempd MPD Client. (From symbian)
Other
4 stars 7 forks source link

Allow controlling playback volume with volume keys? #34

Closed haasn closed 3 years ago

haasn commented 4 years ago

I saw that your fork has the ability to easily change songs from the lock screen, but I'm still missing the ability to easily change playback volume. It would be cool if you could hook up the volume buttons to control playback volume while a song is playing.

This is a feature most other audio players (e.g. unplayer, daedalus, 'Media') seem to have, yet not SMPC/mpd.

haasn commented 4 years ago

After an unreasonable amount of digging through documentation and source code, I managed to track down how this is supposed to work on SailfishOS, and came to the conclusion that this is basically a bug in the way mpd's pulseaudio output interacts with Meego's volume control plugin.

Basically, the default pulseaudio role on SailfishOS is "x-maemo", which is what the module-meego-mainvolume module controls. For some reason, they decided to only hard-code controls for this specific role (as well as "phone"), however, mpd (correctly) sets its media role to "music", which the meego volume plugin happily ignores.

I've worked around this issue by compiling mpd with the line setting the media role commented out, thus allowing it to infer the default media role "x-maego" - and now the volume control buttons work for changing the mpd playback volume. (Side note, SMPC's "volume slider" doesn't get updated in this case, which can lead to unfortunate accidents if you happen to accidentally touch it while it's still set to a high volume!)

One thing I still haven't managed to figure out is how to get it to automatically pause playback if the headphones are unplugged (something that works in other players). Will comment with more findings. But given that this is a bug in the mpd/sailfishOS interaction I'm not sure if this issue is still relevant to SMPC, unless there's something we could do to make the SMPC/mpd user experience better on SailfishOS.

fuchsmich commented 4 years ago

As you said, this is not relevant for SMPC. SMPC is just a remote controller for mpd. Your issue is about the integration of mpd into SailfishOS/Mer itself.

a-dekker commented 4 years ago

Are we talking about running MPD on the phone itself which is causing issues? Reading the volume rocker and emitting volume changes to MPD itself should not be that complicated.

fuchsmich commented 4 years ago

Are we talking about running MPD on the phone itself which is causing issues?

Yes.

Reading the volume rocker and emitting volume changes to MPD itself should not be that complicated.

If the app is active (fullscreen), it's no problem to assign the volume rockers to any action. But does it make sense as well?

a-dekker commented 4 years ago

Yes, it does make sense in a way that you can control the volume of your mpd instance, similar as I can control my remote kodi instance volume via the volume rockers if I want to when I have Kodimote active. But it's not a killer feature for me, I usually control the volume (of kodi) directly via my receiver.

haasn commented 4 years ago

Are we talking about running MPD on the phone itself which is causing issues?

Yeah, that's my use case. (mpd/SMPC is the only media playback solution I've found that doesn't involve unreasonable compromises. For some reason there are no good native SailfishOS music players..)

Reading the volume rocker and emitting volume changes to MPD itself should not be that complicated.

Indeed, it's supposed to "just work", the only reason it didn't is because mpd was too "clever": it set the pulseaudio media role to "music", while SailfishOS for some reason hard-codes the volume rockers to only control streams with role "x-maemo".

But being able to control a remote mpd instance with the volume rocker buttons does also make some amount of sense. It's also not a killer feature for me.

fuchsmich commented 4 years ago

I've worked around this issue by compiling mpd with the line setting the media role commented out, thus allowing it to infer the default media role "x-maego" - and now the volume control buttons work for changing the mpd playback volume. (Side note, SMPC's "volume slider" doesn't get updated in this case, which can lead to unfortunate accidents if you happen to accidentally touch it while it's still set to a high volume!)

In this case I would disable volume control in mpd itself.

EDIT: ...and did you know, you can configure the media role? https://www.musicpd.org/doc/html/plugins.html#pulse-plugin

EDIT2: does this help to control mpd as local musicplayer in sailfish? https://github.com/eonpatapon/mpDris2

haasn commented 4 years ago

EDIT: ...and did you know, you can configure the media role? https://www.musicpd.org/doc/html/plugins.html#pulse-plugin

Cool, that one is new in git master. (Latest tagged release doesn't have it)

EDIT2: does this help to control mpd as local musicplayer in sailfish? https://github.com/eonpatapon/mpDris2

I remember trying that one in the distant past and it not really working smoothly. But I can give it another try.

fuchsmich commented 4 years ago

EDIT2: does this help to control mpd as local musicplayer in sailfish? https://github.com/eonpatapon/mpDris2

I remember trying that one in the distant past and it not really working smoothly. But I can give it another try.

If you are trying this, I guess you have to disable MPRIS in SMPC. Comment this line out. (Which reminds me we should make MPRIS configurable.)

a-dekker commented 3 years ago

Volume key support should be added via https://github.com/a-dekker/smpc/commit/ac80d4a698ddcd087f54553dbded748d982b0e96 It will increase/decrease the volume in steps of 5%. Support can be enabled and disabled. Interacts well with volumeslider.

fuchsmich commented 3 years ago

What does the "resourcehandler" do in this context?

a-dekker commented 3 years ago

It's for being able to claim the volume rocker for your application.

haasn commented 3 years ago

That's awesome, many thanks! Quick question, do you know if you can make it so the volume rocker still works while the display is off? That would make controlling the volume easier while the phone is in your pocket.

On Thu, 20 Aug 2020 06:27:34 -0700, a-dekker notifications@github.com wrote:

It's for being able to claim the volume rocker for your application.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/a-dekker/smpc/issues/34#issuecomment-677664102Non-text part: text/html

a-dekker commented 3 years ago

It now releases control as soon as it is no longer the active app, so it does not block the usage for other uses. Display off is also regarded as a non-active state, but maybe conditions for releasing the control can be changed to take this use case into account. I will have to play with that and see how it works out.

a-dekker commented 3 years ago

I was able to prevent to control release in case the app is active and the screen goes blank. But nevertheless the volume rocker does not respond when the screen is blank. I see the same happening in other apps that control the volume of a remote device (Jupii, Kodimote). In case of local mediaplayers, it does work by default (lockscreen is activated when touching the volume buttons)

a-dekker commented 3 years ago

For the record: I just installed MPD on my SailfishOS phone for testing it myself. Volume control works without problems (slider and rocker). I guess you tried to control the volume of the phone itself, as my approach is to address the MPD volume.

Thaodan commented 2 months ago

For me the option to let smpc control volume keys wasn't working. However setting media_role to "x-maemo" was a workaround to get working volume control.

Sailfish OS 4.5.x Xperia 1 II.