Reputation: 229
I have the following method
private void playRingtone() {
Uri sound = Uri.parse(Constants.ANDROID_RESOURCE_ROOT + this.getPackageName() +
Constants.SLASH_SEPARATOR + R.raw.sound);
this.ringtone = RingtoneManager.getRingtone(this.getApplicationContext(), sound);
this.ringtone.setLooping(Boolean.TRUE);
this.ringtone.play();
}
On line setLooping(Boolean.TRUE);
, the following message is appeared
Call requires API level 28 (current min is 21): android.media.Ringtone#setLooping
Has the Ringtone
instance any other method that replaces setLooping
on APIs lower than 28?
Upvotes: 3
Views: 431
Reputation: 1088
You could try adding a timerTask
inside a scheduleAtFixedRate
to check if it is still playing
It goes something like this
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (!this.ringtone.isPlaying()) {
this.ringtone.play();
}
}
}, 1000, 100);
Where the 1000
is the time when the timer starts to run and 100
is the time for interval
Hope this help
Upvotes: 3
Reputation: 767
No, it does not have a setLooping
method replacement. There is only a play()
method, and that is what you will be forced to work with.
Works Cited https://developer.android.com/reference/kotlin/android/media/Ringtone
Upvotes: 1