Android - Ringtone wont stop playing
I currently start a Ringtone on Android and it plays fine.
However when I try to stop the ringtone it doesn't stop or atleast doesn't stop straight away, it will keep in playing until it just plays out.
Here is how I set up the Ringtone:
int rm = audio_service.getRingerMode();
int vs = audio_service.getVibrateSetting(AudioManager.VIBRATE_TYPE_开发者_Go百科RINGER);
android.os.Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if ((rm == AudioManager.RINGER_MODE_VIBRATE ||
(rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON)))
v.vibrate(vibratePattern,1);
if (audio_service.getStreamVolume(AudioManager.STREAM_RING) > 0) {
oRingtone = RingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI);
oRingtone.setStreamType(AudioManager.STREAM_RING);
oRingtone.play();
}
And here is how I try to stop it
if (CallDialogActivity.oRingtone != null) {
Log.d("RINGTONE", "Into Ringtone if");
Ringtone ringtone = CallDialogActivity.oRingtone;
oRingtone = null;
ringtone.stop();
}
Has anyone come across similiar problems or see any mistakes in my code?
EDIT:
Just to add I have added logging to see if ringtone.isPlaying() returns true or false after I call ringtone.stop() and it returns false, however the tone keeps playing for a couple of seconds (3 - 5 seconds) after before stopping
For anyone that comes across this:
I had to use the RingTone manager to help stop the ringtone.
Adding the following line sorted it out
ringtoneManager.stopPreviousRingtone();
精彩评论