Android 2.3: How do I switch from SCO to A2DP for a capable Bluetooth speaker?

佐手、 提交于 2019-12-23 04:14:06

问题


Now I can get it the app to start playing audio over A2DP and successfully switch to SCO, however when I try to switch back it plays over my phone's speaker instead.

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

回答1:


I can only be of help here by advising that you try to stay away from BT audio path routing. This is a very difficult problem to solve, which is why very few apps (other than the Phone app itself) route BT audio paths, and the few that do try it probably all have some undesirable results.

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

public void setBluetoothA2dpOn (boolean on)

This method is deprecated. Do not use.



来源:https://stackoverflow.com/questions/10920643/android-2-3-how-do-i-switch-from-sco-to-a2dp-for-a-capable-bluetooth-speaker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!