Bluetooth control again

Discussions, support, news

Bluetooth control again

Postby gregko » Fri Mar 30, 2012 11:58 pm

Bluetooth pause/resume buttons no longer work after I upgraded the phone to Android 4 ICS. They worked fine under Gingerbread. Actually many more apps seem to have this problem under ICS, e.g. Audible audiobook player. Do you have any insights into this problem, possible fixes coming? Thanks!

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby gregko » Sun Apr 01, 2012 6:54 pm

FYI, there are also a number of products that handle bluetooth controls correctly under ICS - e.g. neither the built-in Music app, nor PlayerPro and several others I tested from Android Market (or Google Play store now) has this problem, they work correctly. Apparently some small code modification is needed for Bluetooth controls to work under ICS.

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby gregko » Tue Apr 03, 2012 10:20 pm

I found a message thread at:

http://code.google.com/p/android/issues/detail?id=23172

where this issue is discussed and a developer of another app explains how he fixed the issue on ICS. I'll quote this here for your convenience:

Comment 46 by ttab...@gmail.com, Mar 26, 2012
For play/pause, tell your app developers to fix their code. Here's a patch I did for Subsonic. It should be obvious to any dev what they need to change. On a Galaxy Nexus (GSM) with Motorola S305 headset, all buttons work properly now. FWD, BACK, and Call worked fine before. It was just play/pause causing issues.
Code: Select all
--- DownloadServiceLifecycleSupport.java 2012-03-26 14:46:29.000000000 -0600
+++ DownloadServiceLifecycleSupport.java 2012-03-26 14:44:21.000000000 -0600
@@ -210,6 +210,12 @@
             case KeyEvent.KEYCODE_MEDIA_STOP:
                 downloadService.reset();
                 break;
+            case KeyEvent.KEYCODE_MEDIA_PLAY:
+                  downloadService.play();
+                  break;
+            case KeyEvent.KEYCODE_MEDIA_PAUSE:
+                  downloadService.pause();
+                  break;
             default:
                 break;
         }


Hope this will help you find a fix soon. I think the "downloadService" object is specific to his app, the important thing is to respond to "KeyEvent" codes as above.

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby Artem Saveliev » Wed Apr 04, 2012 7:20 am

We'll try but unfortunately I can't promise a fast fix.
Artem Saveliev
 
Posts: 171
Joined: Wed Sep 14, 2011 10:07 am

Re: Bluetooth control again

Postby gregko » Wed Apr 04, 2012 2:25 pm

Thank you for trying, Artem! I looked into the source code of Android 4 Music app (that handles bluetooth controls correctly under ICS) - I find there the code similar to the above as well, in file named MediaButtonIntentReceiver.java:

Code: Select all
package com.android.music;

import android.content.BroadcastReceiver;
// ... stuff removed for this post

public class MediaButtonIntentReceiver extends BroadcastReceiver {

// stuff removed...

@Override
    public void onReceive(Context context, Intent intent) {
        String intentAction = intent.getAction();
        if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
            Intent i = new Intent(context, MediaPlaybackService.class);
            i.setAction(MediaPlaybackService.SERVICECMD);
            i.putExtra(MediaPlaybackService.CMDNAME, MediaPlaybackService.CMDPAUSE);
            context.startService(i);
        } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
            KeyEvent event = (KeyEvent)
                    intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
           
            if (event == null) {
                return;
            }

            int keycode = event.getKeyCode();
            int action = event.getAction();
            long eventtime = event.getEventTime();
            int buttonId = intent.getIntExtra(MediaPlaybackService.CMDNOTIF, 0);

            // single quick press: pause/resume.
            // double press: next track
            // long press: start auto-shuffle mode.

            String command = null;
            switch (keycode) {
                case KeyEvent.KEYCODE_MEDIA_STOP:
                    command = MediaPlaybackService.CMDSTOP;
                    break;
                case KeyEvent.KEYCODE_HEADSETHOOK:
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                    command = MediaPlaybackService.CMDTOGGLEPAUSE;
                    break;
                case KeyEvent.KEYCODE_MEDIA_NEXT:
                    command = MediaPlaybackService.CMDNEXT;
                    break;
                case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                    command = MediaPlaybackService.CMDPREVIOUS;
                    break;
                case KeyEvent.KEYCODE_MEDIA_PAUSE:
                    command = MediaPlaybackService.CMDPAUSE;
                    break;
                case KeyEvent.KEYCODE_MEDIA_PLAY:
                    command = MediaPlaybackService.CMDPLAY;
                    break;
            }
       // stuff removed for this post...
}


Please let me know if I could help any more. I could test on under my phone (Samsung Galaxy S2, AT&T version, i777) under ICS, and if needed also under Gingerbread. I also have an old "passion" phone (original Google Nexus One) running Gingerbread to test if needed. I could even introduce some changes, compile and test myself, if you would share some relevant parts of source code - if necessary under NDA agreement...

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby Klimov.Viktor » Wed Apr 04, 2012 6:56 pm

Hi Greg,

Thank you very much for your help!
We've fixed it, you'll see changes in the next Astro Player release.

Viktor
Klimov.Viktor
 
Posts: 89
Joined: Wed Jun 29, 2011 8:31 am

Re: Bluetooth control again

Postby gregko » Thu Apr 05, 2012 1:23 pm

Great!!! Hurrah! Thank you very much, Victor! I also have a confirmation from another developer, Seany of Moon+Reader, where the bluetooth control starts and stops Text To Speech reading of audiobooks. Sent him exactly the same suggestions as I did send to you - today I got a test version .apk to try and indeed this fix also works for Moon+Reader.

Now if only Audible could implement that as well... I email them many times and get no replies at all. Hell, if they won't fix it soon, I'll buy DRM Converter product and start unprotecting their audiobooks so that I could listen to them in AstroPlayer Nova instead...

Thanks again!

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby gregko » Tue Apr 10, 2012 1:01 pm

I decided to re-post the info below here from another thread, to have all the code changes needed to make Bluetooth controls under ICS work in one place. Artem told me that Astro Player v. 1.141 already contains code changes suggested above, but in my tests under ICS bluetooth controls still don't work. I asked Seany - the author of Moon+ Reader, about any other change he made in his code to make this work under ICS, and here is what he replied:

Hi, You're welcome, just add one line code to onResume() event of the Activity:

((AudioManager)context.getSystemService(Context.AUDIO_SERVICE)).registerMediaButtonEventReceiver(new ComponentName(context.getPackageName(), OpenFile_Receiver.class.getName()));

and replace registerMediaButtonEventReceiver to unRegisterMediaButtonEventReceiver to onDestoryed() event.


Could you please try it and let me test? I could download an unofficial test version of apk file, either Nova or the classic version, and test afterwards, before you make a full release for everyone.

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby gregko » Thu Apr 12, 2012 1:11 pm

FYI, I directed Reed - the author of Akimbo audiobook player - to this thread, by emailing him yesterday evening. He implemented all the changes posted here, and today I got a test version to try under ICS - works perfectly as well. Apparently these code changes (together with the last one I quote in the message above, sent by Seany) are all that's needed to make bluetooth controls work under ICS. Thank you for listening and I'm looking forward to AstroPlayer with this fix as well!

Greg
gregko
 
Posts: 22
Joined: Tue Dec 06, 2011 3:03 pm

Re: Bluetooth control again

Postby Artem Saveliev » Thu Apr 12, 2012 3:20 pm

It's a pity, but we haven't implemented your fix in 1.142. We'll notify you as soon as we'll do it.
Artem Saveliev
 
Posts: 171
Joined: Wed Sep 14, 2011 10:07 am

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron