开发者

Android mediaPlayer asynchronously repeat

开发者 https://www.devze.com 2023-04-12 21:01 出处:网络
I am a little confused on how to manage th开发者_开发问答e mediaplayer functions. I want a sound to repeat for a designated number of seconds. It is intended to be very attention getting. The problem

I am a little confused on how to manage th开发者_开发问答e mediaplayer functions.

I want a sound to repeat for a designated number of seconds. It is intended to be very attention getting. The problem is that I don't know how to make the sound stop. I see that there are Async functions in the MediaPlayer but I don't get it. Should I just do my own Async or CountdownTimer that stops the sounds at the end of the timer?

        MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.telephone_ring_3);
        mediaPlayer.setLooping(true);
        mediaPlayer.setVolume(1.0f, 1.0f);
        mediaPlayer.start();

Insight or best practices appreciated


If there is not some other user initiated event that stops the sound, then yes, I would probably go with a CountdownTimer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号