低于28的API如何在Ringtone实例上启用循环?

我有以下方法

    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();
    }

setLooping(Boolean.TRUE);行上,出现以下消息

  

调用需要API级别28(当前最小值为21):android.media.Ringtone#setLooping

在28以下的API上,Ringtone实例是否有其他方法可以代替setLooping

petar29 回答:低于28的API如何在Ringtone实例上启用循环?

您可以尝试在Linkedlist& Linkedlist::operator=(const Linkedlist& l) { if (this != &l) { this->clear(); for (auto iter = l.head; iter != nullptr; iter = iter->next ) { this->push_back(iter->data); } } return *this; } 内添加timerTask来检查它是否仍在播放

它是这样的

scheduleAtFixedRate

Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { if (!this.ringtone.isPlaying()) { this.ringtone.play(); } } },1000,100); 是计时器开始运行的时间,1000是间隔时间

希望获得帮助

,

否,它没有setLooping方法替换。只有play()方法,这就是您将不得不使用的方法。

引用了https://developer.android.com/reference/kotlin/android/media/Ringtone

的作品
本文链接:https://www.f2er.com/3126506.html

大家都在问