[英]Android - Ringtone wont stop playing
I currently start a Ringtone on Android and it plays fine. 我目前在Android设备上启动了铃声,并且可以正常播放。
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_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 只是为了补充,我添加了日志记录,以查看ringtone.isPlaying()在调用ringtone.stop()之后返回true还是false,并且返回false,但是该音调会在此之后持续播放几秒钟(3-5秒)停止
For anyone that comes across this: 对于遇到此问题的任何人:
I had to use the RingTone manager to help stop the ringtone. 我必须使用RingTone管理器来帮助停止铃声。
Adding the following line sorted it out 添加以下行将其排序
ringtoneManager.stopPreviousRingtone();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.