简体   繁体   English

如何在 Android 中无限循环播放铃声?

[英]How to play ringtone sound in Android with infinite loop?

i want to play the ringtone selected in the settings of the device, but in loop mode.我想播放在设备设置中选择的铃声,但在循环模式下。

here you can see how to play it only once: How to play ringtone/alarm sound in Android在这里你可以看到如何只播放一次: 如何在 Android 中播放铃声/闹钟声音

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

I need to make it play in loop mode, but i don't know how to do it...我需要让它在循环模式下播放,但我不知道该怎么做...

thanks谢谢

It seems the simplest way is to create a MediaPlayer from the Uri returned from RingtoneManager , and set it to loop.似乎最简单的方法是从RingtoneManager返回的Uri创建一个MediaPlayer ,并将其设置为循环。

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer player = MediaPlayer.create(this, notification);
player.setLooping(true);
player.start();

By using setLooping(true) you can achieve this:通过使用 setLooping(true) 您可以实现:

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mMediaPlayer.setDataSource(this, alert);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM