MEDIA_BUTTON handle not working when starting bluetoothSCO

I am using a bluetooth speaker audio recorder. The bluetooth speaker has a multimedia button like play / pause, next, previous. I start the play button to record and click again to stop. But the problem is that when using mAudioManager.startBluetoothSco () to use bluetooth microphone for recording, Media_button receiver no longer works, cannot receive any event.

Below is the source code: Recipient registration:

    ((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(
            new ComponentName(
                    this,
                    MediaButtonReceiver.class.getName()));

      

MediaButtonReceiver:

@Override
    public void onReceive(Context context, Intent intent) {
        Log.d("MediaButtonReceiver", "onReceive Media button!" );
        KeyEvent key = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        Log.d("MediaButtonReceiver", "Media button! action: [" + key.getAction() + "] key code: [" + key.getKeyCode() + "]");
        if(key.getAction() == KeyEvent.ACTION_UP) {
            int action = fromKeyCodeToAction(key.getKeyCode());
            switch (action) {
                case ACTION_START_STOP_TALKING:
                    LogUtils.LOGD("MediaButtonReceiver", "Action start/stop");
                    startStopRecord();
                    break;

      

... I am handling some logic in the listener to check the current state entry or not. and start the service to start or stop recording. And this is the code to start recording.

if (isBluetoothHeadsetConnected) {
                LogUtils.LOGI("Bluetooth", "record using headset");
                //we just start recording when the audio state is connected
                mContext.registerReceiver(mBluetoothAudioStateBroadcastReceiver, mBluetoothAudioStateIntentFilter);
                LogUtils.LOGI("Bluetooth", "startBluetoothSco");
                mAudioManager.startBluetoothSco();
                mAudioManager.setBluetoothScoOn(true);
            } else {
                LogUtils.LOGI("Bluetooth", "record normally ");
                mAudioManager.setMode(AudioManager.MODE_NORMAL);
                mAudioManager.setBluetoothScoOn(false);
                handleStartRecordJob();
            }

      

If I remove startBluetoothSco () the receiver works fine, but the app uses the device microphone instead of the bluetooth speaker. If I don't delete, the receiver no longer works and I cannot stop the recorder. Do you have a solution to work arround?

+3
android record bluetooth


source to share


No one has answered this question yet

Check out similar questions:

22
Using Android RecognizerIntent with Bluetooth Headset
fourteen
How to capture key events from bluetooth headset using android
4
KeyEvent.KEYCODE_MEDIA_NEXT not received if no sound is playing
3
Android Bluetooth Audio Play and Recording
1
iOS How to play beep on speaker while recording
1
How can I detect that a disconnected Bluetooth audio device is the current music streaming device?
0
Understanding Bluetooth Headset Connection with Android
0
Google Now accepts bluetooth broadcast
0
Android bluetooth SCO sound cannot be heard for bluetooth headset



All Articles
Loading...
X
Show
Funny
Dev
Pics