Play sound continuously onTouch()

前端 未结 4 1565
傲寒
傲寒 2021-01-20 02:48

I want to play a gun shot sound continuously by onTouch. I am doing this for automatic gun sounds. So i have problem with there is delay in sound looping. which does not giv

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-20 03:13

    use SoundPool instead of MediaPlayer.

    SoundPool sP = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
    gunshot = sP.load(this, R.raw.gunshot, 1);
    sP.play(gunshot, 1, 1, 0, 0, 1);
    

提交回复
热议问题