[英]Ringtone playing too long
我正在使用具有RingtonePreference的RingtoneManager。 当我使用默认铃声时,没有问题,但是当我使用配置的铃声时,它会播放几分钟...我不知道这首歌的持续时间是分钟还是循环播放...
这是我的代码:
private static void playNotificationSound(Context context) {
RingtoneManager rm = new RingtoneManager(context);
String ringtone = MySharedPreferences.ringtone(context);
Uri uri = null;
if(ringtone == null)
uri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
else
uri = Uri.parse(ringtone);
if (uri != null) {
Ringtone rt = RingtoneManager.getRingtone(context, uri);
if (rt != null) {
rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
rt.play();
}
}
}
我用它来播放带有通知的歌曲,但我不想手机播放5分钟...
尝试添加以下行。
ringtoneManager.stopPreviousRingtone();
你可以使用这样的线程吗?
if (rt != null) {
rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
rt.play();
}
Thread myThread = new Thread() {
int wait = 0;
@Override
public void run() {
try {
super.run();
while (wait < 5000) {
sleep(500);
wait += 500;
}
} catch (Exception e) {
} finally {
if (rt.isPlaying())
rt.stop();
}
}
};
myThread.start();
我找到了另一个解决方案,我设置了notification.sound = uri; 并且不再使用RingtoneManager。
带有notification.flags | = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
但是歌曲仍然循环播放。 铃声可能真的只有5分钟了吗? 还是可以将铃声配置为循环歌曲?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.