7
votes

I have made android audio application. And now some users reporting that app is not responding on media buttons (play, pause, next) when they connected the device via Bluetooth in the car.

At the same time, I tested app with Bluetooth speaker - play/pause button works as needed.

Are there any differences between Bluetooth speaker and Bluetooth radio in the car??? It is very strange

I'm using ExoPlayer and have this code for handling media buttons:

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, getApplicationContext(), MediaButtonReceiver.class);
    mSession.setMediaButtonReceiver(PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0));
    MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mSession, new DefaultPlaybackController(), false, null);
    mediaSessionConnector.setQueueNavigator(new QueueNavigatorAdapter() {
        @Override
        public void onSkipToPrevious(Player player) {
            playPrevious();
        }

        @Override
        public void onSkipToNext(Player player) {
            playNext();
        }
    });
    mediaSessionConnector.setPlayer(mPlayer, null);

and

    mPlayer.prepare(source);
    mSession.setActive(true);
    mPlayer.setPlayWhenReady(true);

I know about AudioManager.registerMediaButtonEventReceiver() and handling KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE etc. but I was sure mSession.setMediaButtonReceiver && MediaSessionConnector do it for me.

Maybe I'm wrong and it is not enough?

minSdkVersion 21

1
Have you tried turning if off and on again?Michael
No, I have no possibility to reproduce this bugDmitry

1 Answers

3
votes

As I remember, you need to perform something like this:

if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode()==25)

based on Bluetooth device you are working with, in this case, Bluetooth radio in the car. You need manual for car radio device.