0

I am trying to program a sound app where on button click I would like to play 3-4 sound files one after the other. How can this be done? Also I would like to increase the time of play of the files. Is this where the loop variable in play function used??

Here is part of code I have done with SoundPool. However the files all play simultaneously :(

        public void onClick(View v){
            //check for scan button
            if(v.getId()==R.id.playbutton){
                queueSound(1000);
                sound.changePitchfile3(R.raw.a0);
                queueSound(5000);
                sound.changePitchfile2(R.raw.a1);
                queueSound(10000);
                sound.changePitchfile3(R.raw.a3);

            }
        }
    });

}
 private void queueSound(final long delay) {
        new Handler().postDelayed(new Runnable() {
          @Override
          public void run() {
          }}, delay);

public void changePitchfile1(int res1) {
    int soundId = (Integer) mSounds.get(res1);
    this.myPlayer.play(soundId, 1, 1, 0, 0,1.125f);
}
user900785
  • 423
  • 3
  • 14
  • 32
  • 1
    I believe `SoundPool` does not provide a listener for when the play has finished, so you would have to know the length of your sounds in advance and set up your Handlers accordingly. I would recommend using a `MediaPlayer` with an `onCompleteListener` as an alternative. – Ken Wolf Jul 17 '13 at 09:41
  • I need to be able to adjust the pitch and therefore I chose SoundPool in the first place. Is this possible with MediaPlayer? Also my sound file is about 6 MB large – user900785 Jul 17 '13 at 10:55
  • 2
    Sorry, I didn't catch that. No, only `SoundPool` supports pitch change, so you will have to use that. You are on the right track but your call to `changePitchfile1` should be within the `Runnable` - whatever is in the `Runnable()` will execute after the delay. – Ken Wolf Jul 17 '13 at 11:02

0 Answers0