嗨我想完全停止音乐,当有人打电话给我,如果我现在打电话给某人就像应用程序把音量调低,我仍然可以在背景中听很低但是我想停止音乐继续我现在的代码:
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
wasPlayingBeforePhoneCall = radioService.isPlaying();
radioService.stop();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
if (wasPlayingBeforePhoneCall) {
radioService.play();
}
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
// A call is dialing, active or on hold
wasPlayingBeforePhoneCall = radioService.isPlaying();
radioService.stop();
}
super.onCallStateChanged(state, incomingNumber);
}
};
播放方法:
public void play() {
if (hasConnectivity()) {
if (getCurrentStationType().equals(TYPE_AAC)) {
prepare();
} else {
if (isPrepared) {
isRadioPlaying = true;
mediaPlayer.start();
System.out.println("RadioService: play");
setStatus(STATUS_PLAYING);
sendBroadcast(new Intent(MODE_PLAYING));
} else {
prepare();
}
}
} else
sendBroadcast(new Intent(MODE_STOPPED));
}
停止方法:
public void stop() {
timeCounter = -1;
resetMetadata();
isPrepared = false;
System.out.println("RadioService: stop");
if (getCurrentStationType().equals(TYPE_AAC)) {
if (isRadioPlaying) {
isRadioPlaying = false;
multiPlayer.stop();
}
// else
// sendBroadcast(new Intent(MODE_STOPPED));
} else {
mediaPlayer.stop();
mediaPlayer.reset();
isRadioPlaying = false;
setStatus(STATUS_STOPPED);
sendBroadcast(new Intent(MODE_STOPPED));
}
// clearNotification();
}
我做错了什么?
谢谢。