How to play ringtone sound in Android with infinite loop?
It seems the simplest way is to create a MediaPlayer
from the Uri
returned from RingtoneManager
, and set it to loop.
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:
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mMediaPlayer.setDataSource(this, alert);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();