Reputation: 1312
i want to route the voice to Bluetooth.
below code is my Player.
AudioTrack at;
try {
minbuffer = AudioTrack.getMinBufferSize(8000,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT);
if (minbuffer < VOICE_SPEECH_SIZE)
minbuffer = VOICE_SPEECH_SIZE;
at = new AudioTrack(AudioManager.STREAM_VOICE_CALL, 8000,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, minbuffer,
AudioTrack.MODE_STREAM);
at.play();
while (PlayOutblinker == Thread.currentThread()) {
byte[] tt = vbuff.take();
at.write(tt, 0, tt.length);
}
} finally {
at.stop();
at.release();
at = null;
}
i searched and find below :
public static void SetRouteBT(Context context, boolean isRoute) {// TODO
AudioManager mAudioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.startBluetoothSco();
mAudioManager.setBluetoothScoOn(isRoute);
}
but it does not work.
when i setBluetoothScoOn(true)
voice does not route but disconnect from speaker and microphone.
where is the problem?
Upvotes: 0
Views: 976
Reputation: 1312
the function should change to below code :
public static void SetRouteSco(Context context, boolean isRoute) {
AudioManager mAudioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setBluetoothScoOn(isRoute);
if (isRoute)
mAudioManager.startBluetoothSco();
else
mAudioManager.stopBluetoothSco();
}
and i need below permissions too.
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Upvotes: 1