0

我想将语音路由到蓝牙。

下面的代码是我的播放器。

    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;
        }

我搜索并找到以下内容:

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);
}

但它不起作用。当我setBluetoothScoOn(true)的声音没有路由但与扬声器和麦克风断开连接时。问题出在哪里?

4

1 回答 1

1

该函数应更改为以下代码:

    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();
}

我也需要以下权限。

<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
于 2012-12-13T13:35:31.243 回答