1
我正在尝试将我在我的应用中播放的所有音频重定向到蓝牙扬声器。起初我配对的蓝牙设备,然后我尝试“说”的audioManager,我在剧中扮演的所有音频应送蓝牙speeker:如何将音频从Android设备重定向到蓝牙speeker
private final BluetoothAdapter _bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
public void pairBluetoothDevice(BluetoothDevice bluetoothDevice)
{
BluetoothSocket socket= bluetoothDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString("0000111E-0000-1000-8000-00805F9B34FB"));
socket.connect();
_bluetoothAdapter.getProfileProxy(_appContext, _profileListener, BluetoothProfile.HEADSET);
}
private BluetoothProfile.ServiceListener _profileListener = new BluetoothProfile.ServiceListener()
{
public void onServiceConnected(int profile, BluetoothProfile proxy)
{
if (profile == BluetoothProfile.HEADSET)
{
_bluetoothHeadset = (BluetoothHeadset) proxy;
_bluetoothHeadset.startVoiceRecognition(_device);
AudioManager audioManager = (AudioManager) _appContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.startBluetoothSco();
audioManager.setBluetoothScoOn(true);
audioManager.setSpeakerphoneOn(false);
}
}
public void onServiceDisconnected(int profile)
{
if (profile == BluetoothProfile.HEADSET)
{
AudioManager audioManager= (AudioManager) _appContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setBluetoothScoOn(false);
audioManager.stopBluetoothSco();
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
_bluetoothHeadset.stopVoiceRecognition(_device);
_bluetoothHeadset= null;
}
}
};
当我播放音频...
_soundPool.play(_soundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed);
...我什么也没听到。
感谢您的任何提示:-)