问题
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