Page 1 of 2
Android client doesn't handle media button events correctly
Posted:
Thu Apr 18, 2013 1:38 am
by rage4order
This problem has existed for a very long time, but I'm only now getting around to reporting it, because it's getting *very* irritating. Basically, the Android Subsonic app hogs the focus of the media controls, and never releases them. The net result is that it always responds to pause/play and skip events even though they are supposed to be routed to another app. For example, start playing an album using the Google Play Music app, the press skip forward on an AVRCP capable device (like Bluetooth headphones) and instead of the Play app skipping forward, Subsonic will start playing a track that was queued up last time that it had run. At this point there are 2 overlapping music streams playing. Pressing pause on the Bluetooth headphones will pause the Subsonic playback, and the Google Play app continues to play the same track as before, because it never received any of the media button events.
I haven't looked at the code in much detail yet, but I suspect that the Subsonic app doesn't unregister itself as a preferred media button responder, which it should do every time the app's activity closes or when background playback ends.
This article provides a good description how this SHOULD work:
http://android-developers.blogspot.com/ ... nicer.html
Re: Android client doesn't handle media button events correc
Posted:
Thu Apr 18, 2013 2:02 am
by daneren2005
Except when a user pauses through the headset and then tries to play again it should most definitely respond to it. While the background service is running there isn't really any way to differentiate between what it should do and not do. Your best bet is to do an explicit menu exit when you are done.
Sent from my HTC One X using Tapatalk 2
Re: Android client doesn't handle media button events correc
Posted:
Thu Apr 18, 2013 4:24 pm
by rage4order
Yes, it is true that your background service should respond to resume playback, however it is supposed to be tied to audio focus. As long as the background playback service has the focus, then it should receive the media playback button events. Once this focus is lost, it should release them. If the audio focus loss is transient, such as in case of ducking, then the app can go ahead and hold on to the button events, but sadly Subsonic doesn't handle ducking either (that's another feature that I dearly wish would be implemented.) The Android developer documentation talks about this stuff here:
http://developer.android.com/training/m ... focus.htmlHaving now downloaded the Subsonic source code, I think I understand how this bug happens. I searched to find where the application calls the unregisterMediaButtonEventReceiver() and the ONLY place I found the call was inside of the SettingsActivity. On the other hand, the registerMediaButtonEventReceiver() is called in the SettingsActivity, SubsonicTabActivity, BluetoothIntentReceiver, and DownloadServiceLivecycleSupport. That right there tells me that Subsonic is not calling the unregister method in all the places where it should. Since there are 4 different classes that register as receivers, they get put on the registered receiver stack, and so even if you uncheck the preference in settings to disable the media buttons, the other classes are still registered as receivers and consequently, the app always hogs the media buttons. This is exactly the behavior I'm seeing, since I have the "Media Buttons" setting unchecked, but the app still responds to the buttons. The only way to keep Subsonic from constantly taking over all media button events is to completely uninstall the application. This is clearly not how it should work.
Re: Android client doesn't handle media button events correc
Posted:
Mon Apr 29, 2013 2:55 pm
by rage4order
Well, in the spirit of open source, this was the proverbial "itch" that I had to scratch, so I took it upon myself and fixed it. The media buttons now respond when the application has audio focus, and they are released when focus is permanently lost. It will also correctly stop playing when another application (such as Google Play Music) begins to play instead. In the process, I also added the audio ducking support, so now when Google Maps navigation speaks directions, Subsonic will turn down the playback volume to 10% and turn it back up when focus is returned to the app. Over all, it's quite an improvement over the stock app.
If Sindre would would be interested in including these fixes in the next market version of the app, I can provide the source code patches. Just let me know.
Re: Android client doesn't handle media button events correc
Posted:
Mon Apr 29, 2013 5:05 pm
by jsonnabend
Rage4order, could you post the fixed apk here? The bugs you describe are driving me nuts.
Re: Android client doesn't handle media button events correc
Posted:
Mon Apr 29, 2013 10:37 pm
by rage4order
Here it is.
EDIT: deleted attachment. Latest version later in the thread.
Re: Android client doesn't handle media button events correc
Posted:
Mon Apr 29, 2013 11:10 pm
by daneren2005
Do you have your changes up anywhere online? I would like to look at them and see if there is anything beyond what I already do and want to incorporate my branch.
Re: Android client doesn't handle media button events correc
Posted:
Mon Apr 29, 2013 11:14 pm
by rage4order
No I don't have it posted anywhere, but I can send you the diff, that you can use to patch the Subsonic source code.
Re: Android client doesn't handle media button events correc
Posted:
Tue Apr 30, 2013 4:21 am
by daneren2005
Sure, can you PM it to me (or post it here, don't care)?
Re: Android client doesn't handle media button events correc
Posted:
Fri May 10, 2013 6:06 pm
by rage4order
Here's an updated version. I found a small bug, where the app would sometimes spontaneously begin playing after a phone call, or Google voice search, so I zapped it. (It had to do with regaining transient audio focus.)
EDIT: deleted attachment. Latest version later in the thread.
Re: Android client doesn't handle media button events correc
Posted:
Wed May 29, 2013 1:13 pm
by parlance
Just wanted to say thanks for doing this. This has been driving me nuts as well with my Asteroid android based deck in my car. These changes need to get folder into the main source code.
Re: Android client doesn't handle media button events correc
Posted:
Wed May 29, 2013 5:45 pm
by rage4order
You're welcome. Here's an updated version of the package that merges in Sindre's latest changes, which add support for MX Player.
Edit: deleted attachment, because I built a new one. See next message.
Re: Android client doesn't handle media button events correc
Posted:
Mon Jun 10, 2013 5:08 pm
by rage4order
My apologies, the previous build I had posted was defective. When I built it, I had done an repository sync, but apparently didn't get all of the changes, so even though the app built and ran, there were problems with server configuration. It worked fine for me, so I posted the update, but this weekend I discovered that there were problems. Here's a new build, which includes my media button changes, and is synced with the subsonic repository as of today.
EDIT: see end of thread for up-to-date build
Re: Android client doesn't handle media button events correc
Posted:
Wed Jul 31, 2013 2:24 am
by antonmos
Thanks for sharing this! Have you contacted Sindre about pulling in these fixes?
Posted:
Wed Jul 31, 2013 3:23 am
by rage4order
I only mentioned here in this thread, but I figured he would see it. I don't know if he has any formal way of summiting patches, but I'd gladly provide them if he wanted to include them in the next official build.
Sent from my Nexus 7 using Tapatalk HD