Routing audio to Bluetooth Headset (non-A2DP) on Android

后端 未结 5 772
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 21:51

I have a non-A2DP single ear BT headset (Plantronics 510) and would like to use it with my Android HTC Magic to listen to low quality audio like podcasts/audio books.

Af

相关标签:
5条回答
  • 2021-01-29 22:08

    Cannot see a clear accepted working application so putting a new answer. This application routes music and audio to Non A2dp headsets. Try my application and find the source code also in github for reference code. https://github.com/sauravpradhan/AnySound2BT

    0 讨论(0)
  • 2021-01-29 22:16

    This thread may be long dead but for those who might be trying the same thing, some notes from the AudioManager docs may be useful. It looks like the missing element is the startBluetoothSco() command but there are restrictions on the use of this channel. From the Android Dev site here:

    public void startBluetoothSco () Since: API Level 8 Start bluetooth SCO audio connection.

    Requires Permission: MODIFY_AUDIO_SETTINGS.

    This method can be used by applications wanting to send and received audio to/from a bluetooth SCO headset while the phone is not in call.

    As the SCO connection establishment can take several seconds, applications should not rely on the connection to be available when the method returns but instead register to receive the intent ACTION_SCO_AUDIO_STATE_CHANGED and wait for the state to be SCO_AUDIO_STATE_CONNECTED.

    As the connection is not guaranteed to succeed, applications must wait for this intent with a timeout.

    When finished with the SCO connection or if the establishment times out, the application must call stopBluetoothSco() to clear the request and turn down the bluetooth connection.

    Even if a SCO connection is established, the following restrictions apply on audio output streams so that they can be routed to SCO headset: - the stream type must be STREAM_VOICE_CALL - the format must be mono - the sampling must be 16kHz or 8kHz

    The following restrictions apply on input streams: - the format must be mono - the sampling must be 8kHz

    Note that the phone application always has the priority on the usage of the SCO connection for telephony. If this method is called while the phone is in call it will be ignored. Similarly, if a call is received or sent while an application is using the SCO connection, the connection will be lost for the application and NOT returned automatically when the call ends.

    See Also stopBluetoothSco() ACTION_SCO_AUDIO_STATE_CHANGED

    Note that I have not tested this, I'm just passing along a lead I found in researching a similar project. I think Jayesh was close to the solution and the restrictions above may have been what was keeping it from working.

    0 讨论(0)
  • 2021-01-29 22:17

    Great Work it is working fine for me please do bit modification in your code it'll work perfectly i.e.

    mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); 
    
    to 
    
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    
    0 讨论(0)
  • 2021-01-29 22:22

    To turn on:

     localAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
     localAudioManager.setMode(0);
     localAudioManager.setBluetoothScoOn(true);
     localAudioManager.startBluetoothSco();
     localAudioManager.setMode(AudioManager.MODE_IN_CALL);
    

    To turn off:

     localAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
     localAudioManager.setBluetoothScoOn(false);
     localAudioManager.stopBluetoothSco();
     localAudioManager.setMode(AudioManager.MODE_NORMAL);
    

    I took it from here

    0 讨论(0)
  • 2021-01-29 22:25

    There should be a ALSA route path configured for Media player, so that it can open a different audio path and then route your audio to BT headset.

    0 讨论(0)
提交回复
热议问题