Delay between button click and sound

前端 未结 1 541
既然无缘
既然无缘 2021-01-29 04:23

I do not quite understand why there is a delay between the button click and sound.

Following is my code

    button = (Button) findViewById(R.id.playBtn);         


        
相关标签:
1条回答
  • 2021-01-29 04:48

    I think you should consider using SoundPool instead.

        SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
        HashMap<Integer, Integer> soundPoolMap soundPoolMap = new HashMap<Integer, Integer>();
        soundPoolMap.put(soundID, soundPool.load(this, R.raw.your_sound, 1));
    

    And then you can play the sound using:

    soundPool.play(soundId, 1, 1, 1, 0, 0);
    
    0 讨论(0)
提交回复
热议问题