Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop / repeat the current ringtone in Android from an application?

Tags:

android

I am writing an application on android 4.0 which will play the current ringtone when I press a button.

But in the ringtone is played only one time. I need it to repeat for a few times.

My current code:

Uri notifi = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
final Ringtone r = RingtoneManager.getRingtone(c, notifi);
r.play();
like image 355
krrakesh16 Avatar asked Sep 05 '12 09:09

krrakesh16


People also ask

How do you repeat ringtones on Android?

Member. Upload your MP3, it converts it to OGG format and then drop this into your ringtones folder and it will now loop! Besides converting the mp3 to ogg I had to add a tag/field called “ANDROID_LOOP”, and set it to “true”. I used foobar2000 on Windows to do this.


1 Answers

You can have a timer regularly check if the ringtone is still playing. For example, every second:

mRingtone.play();
mTimer = new Timer();
mTimer.scheduleAtFixedRate(new TimerTask() {
    public void run() {
        if (!mRingtone.isPlaying()) {
            mRingtone.play();
        }
    }
}, 1000*1, 1000*1);
like image 76
xStan Avatar answered Sep 18 '22 10:09

xStan