我用服务开发基本的无线电流应用。来电后,无线电流继续但声音播放顶级扬声器。我想从所有扬声器播放。如何做到这一点?
答案 0 :(得分:0)
private final PhoneStateListener phoneListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
try {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING: {
//PAUSE
if(BackgroundAudioService.mediaPlayer!=null){
BackgroundAudioService.mediaPlayer.pause();}
Log.i("pause","pause");
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
break;
}
case TelephonyManager.CALL_STATE_IDLE: {
//PLAY
if(BackgroundAudioService.mediaPlayer!=null){
BackgroundAudioService.mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
BackgroundAudioService.mediaPlayer.start();
Log.i("play","play");
}
break;
}
default: { }
}
} catch (Exception ex) {
}
}
};