2014-08-27 83 views
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); 

...我什麼也沒聽到。

感謝您的任何提示:-)

回答

1

我發現了以下解決方法: 我打開默認的藍牙設置,我可以配對藍牙揚聲器和比音頻將自動發送到揚聲器。

startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS)); 
相關問題