I try to play a device ringtone one time with the MediaPlayer class (I have to use MediaPlayer as I use the ringtones together with other audio sources in my app) So i try the following to play a random ringtone yet I cant stop it looping, it keeps playing. Is it possible to play a ringtone only one time with MediaPlayer.
Thanks
try {
RingtoneManager mRing = new RingtoneManager(RingtoneActivity.this);
int mNumberOfRingtones = mRing.getCursor().getCount();
Uri mRingToneUri = mRing.getRingtoneUri((int) (Math.random() * mNumberOfRingtones));
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(RingtoneActivity.this, mRingToneUri);
mMediaPlayer.prepare();
mMediaPlayer.setLooping(false);
mMediaPlayer.start();
} catch (Exception ignore) {
}
UPDATE:
I just have posted a new question related to this one as I was able to find the specific cause of the trouble in my case.