3

The problem is that MediaSession.Callback()'s method onMediaButtonEvent() is not called after startBluetoothSco() method call.
So, I use this code:

mMediaSession.setCallback(new MediaSession.Callback() {
    public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) {
        Logging.d(TAG, "onMediaButtonEvent");
        return super.onMediaButtonEvent(mediaButtonIntent);
    }

        public void onPause() {
           Logging.d(TAG, "onPause");
           super.onPause();
        }

        public void onPlay() {
           Logging.d(TAG, "onPlay");
           super.onPlay();
        }

        public void onStop() {
            Logging.d(TAG, "onStop");
            super.onStop();
        }
});
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
PlaybackState state = new PlaybackState.Builder()
        .setActions(                PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE |
                                    PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PAUSE |
                                    PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
        .setState(PlaybackState.STATE_STOPPED, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 0)
        .build();
mMediaSession.setPlaybackState(state);
mMediaSession.setActive(true);

onMediaButtonEvent() method is called every time after pressing headset button, but after

mAudioManager.startBluetoothSco();
it is not calling anymore. It will be callable only after
mAudioManager.stopBluetoothSco();
What is the solution to this problem?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.