Android client doesn't handle media button events correctly

Got an idea? Missing something? Post your feature request here.

Moderator: moderators

Android client doesn't handle media button events correctly

Postby rage4order » Thu Apr 18, 2013 1:38 am

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
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby daneren2005 » Thu Apr 18, 2013 2:02 am

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
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Android client doesn't handle media button events correc

Postby rage4order » Thu Apr 18, 2013 4:24 pm

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.html

Having 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.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby rage4order » Mon Apr 29, 2013 2:55 pm

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. :D

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.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby jsonnabend » Mon Apr 29, 2013 5:05 pm

Rage4order, could you post the fixed apk here? The bugs you describe are driving me nuts.
jsonnabend
 
Posts: 42
Joined: Wed May 23, 2012 3:18 am

Re: Android client doesn't handle media button events correc

Postby rage4order » Mon Apr 29, 2013 10:37 pm

Here it is.
EDIT: deleted attachment. Latest version later in the thread.
Last edited by rage4order on Fri Aug 16, 2013 2:10 pm, edited 1 time in total.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby daneren2005 » Mon Apr 29, 2013 11:10 pm

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.
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Android client doesn't handle media button events correc

Postby rage4order » Mon Apr 29, 2013 11:14 pm

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.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby daneren2005 » Tue Apr 30, 2013 4:21 am

Sure, can you PM it to me (or post it here, don't care)?
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm

Re: Android client doesn't handle media button events correc

Postby rage4order » Fri May 10, 2013 6:06 pm

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.
Last edited by rage4order on Fri Aug 16, 2013 2:10 pm, edited 1 time in total.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby parlance » Wed May 29, 2013 1:13 pm

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.
parlance
 
Posts: 6
Joined: Tue Nov 23, 2010 6:40 am

Re: Android client doesn't handle media button events correc

Postby rage4order » Wed May 29, 2013 5:45 pm

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.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby rage4order » Mon Jun 10, 2013 5:08 pm

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
Last edited by rage4order on Fri Nov 08, 2013 8:31 pm, edited 1 time in total.
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Re: Android client doesn't handle media button events correc

Postby antonmos » Wed Jul 31, 2013 2:24 am

Thanks for sharing this! Have you contacted Sindre about pulling in these fixes?
antonmos
 
Posts: 3
Joined: Sat Feb 23, 2013 11:59 pm

Postby rage4order » Wed Jul 31, 2013 3:23 am

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
rage4order
 
Posts: 33
Joined: Mon Jun 29, 2009 8:58 pm

Next

Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 3 guests