Android 按钮点击和声音之间的延迟

Android 按钮点击和声音之间的延迟,android,Android,我不太明白为什么按钮点击和声音之间会有延迟 下面是我的代码 button = (Button) findViewById(R.id.playBtn); final MediaPlayer playButtonClick = MediaPlayer.create(this, R.raw.buttonsound); button.setOnClickListener(new View.OnClickListener() { @Override

我不太明白为什么按钮点击和声音之间会有延迟

下面是我的代码

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

    final MediaPlayer playButtonClick = MediaPlayer.create(this, R.raw.buttonsound);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            playButtonClick.start();

            Intent browserIntent =
                    new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
            startActivity(browserIntent);

        }
    }); 

<无论如何,我可以减少延迟吗?

< P>我想你应该考虑使用声池。

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

这是因为缓冲区的大小。也许这可以帮助你:
soundPool.play(soundId, 1, 1, 1, 0, 0);