play sound file with a delay and adjust time in android

久未见 提交于 2020-01-06 11:25:59

问题


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);
}

来源:https://stackoverflow.com/questions/17687314/play-sound-file-with-a-delay-and-adjust-time-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!