• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

playing the same sound repeatedly

BananoTron

Member
Dec 1, 2008
50
0
i have the following problem:
when i try to play a sound over and over again, it sometimes (actually most times) is not played.
the documentation says that one should use the media player in the following sequence if a sound should be played several times:
mediaPlayer.start()
mediaPlayer.stop()
mediaPlayer.reset()
mediaPlayer.prepare()
mediaPlayer.start()
...

is this the wrong approach? is there a more performant way to reset the pointer in the sound sample so that it can be played from the beginning?
i tried using mediaPlayer.seekTo(0); but it didn't help.
 
Could it be that you are calling stop() before the sound engine has had time to load and play the sample?

nope. i checked that using logging statements.
after creating the sound i call:
start();
start();
start();

(with a short waiting time in between)

i also tried
seekTo(0);
start();
seekTo(0);
start();
seekTo(0);
start();

but with the same result.

maybe i'm using the wrong approach. what is the best practice to load several sounds, cache them and play them repeatedly in a game?
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones