1

现在我可以让应用程序开始通过 A2DP 播放音频并成功切换到 SCO,但是当我尝试切换回来时,它会通过手机的扬声器播放。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    layout = (RelativeLayout) findViewById(R.id.layout);
    text = (TextView) findViewById(R.id.editText1);
    scoSwitch = (ToggleButton) findViewById(R.id.switch1);
    try {
        mp1 = MediaPlayer.create(this, R.raw.jc_cm);
        mp2 = MediaPlayer.create(this, R.raw.rp);
        amanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        //amanager.setBluetoothA2dpOn(true);
                } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void onSCOswitch(View view){
    if (scoSwitch.isChecked()){
        amanager.setBluetoothScoOn(true);
        amanager.startBluetoothSco();
        Log.d("Bluetooth", "SCO on");
        amanager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    }
    else{
        amanager.stopBluetoothSco();
        amanager.setBluetoothScoOn(false);
        amanager.setBluetoothA2dpOn(true);
        Log.d("Bluetooth", "SCO off");
        amanager.setMode(AudioManager.MODE_NORMAL);
    }
} 
4

1 回答 1

0

我只能通过建议您尽量远离 BT 音频路径路由来提供帮助。这是一个非常难以解决的问题,这就是为什么很少有应用程序(除了电话应用程序本身)路由 BT 音频路径,而少数尝试它的应用程序可能都有一些不良结果。

根据http://developer.android.com/reference/android/media/AudioManager.html#setBluetoothA2dpOn(boolean ):

公共无效 setBluetoothA2dpOn(布尔值)

此方法已弃用。不使用。

于 2012-08-21T23:05:48.883 回答