1. Check out our app, Forums for Android! Download and leave feedback here!

playing the same sound repeatedly

Discussion in 'Android Apps & Games' started by BananoTron, Dec 8, 2008.

  1. BananoTron

    BananoTron Well-Known Member
    Thread Starter
    15

    Dec 1, 2008
    50
    0
    15
    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
    88

    Dec 2, 2008
    699
    49
    88
    Male
    Senior software developer
    Northamptonshire
    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
    Thread Starter
    15

    Dec 1, 2008
    50
    0
    15
    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...