1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

playing the same sound repeatedly


Last Updated:

  1. BananoTron

    BananoTron Well-Known Member This Topic's Starter

    Joined:
    Dec 1, 2008
    Messages:
    50
    Likes Received:
    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.
     

    Advertisement
  2. Ageless Stranger

    Ageless Stranger Well-Known Member

    Joined:
    Dec 2, 2008
    Messages:
    699
    Likes Received:
    49
    Could it be that you are calling stop() before the sound engine has had time to load and play the sample?
     
  3. BananoTron

    BananoTron Well-Known Member This Topic's Starter

    Joined:
    Dec 1, 2008
    Messages:
    50
    Likes Received:
    0
    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?
     

Share This Page

Loading...