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.
精彩评论