Android的播放延迟后的声音声音、Android

由网友(Rebekah)分享简介:我要播放声音的GUI事件,如单击按钮等。为此,我呼吁来自的WebView以下本土code:I have to play sounds on GUI events, like clicking buttons etc. For this purpose, I call the following native code...

我要播放声音的GUI事件,如单击按钮等。为此,我呼吁来自的WebView以下本土code:

I have to play sounds on GUI events, like clicking buttons etc. For this purpose, I call the following native code from WebView:

MediaPlayer _SoundPlayer = new MediaPlayer();
private void playSound(String sound)
{
    _SoundPlayer.reset();
    try
    {
        AssetFileDescriptor afd = getAssets().openFd("sound/" + sound + ".mp3");
        _SoundPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        _SoundPlayer.prepare();
        _SoundPlayer.start();
    }
    catch (Exception e) { }
}

现在的问题是有延迟〜一个事件,它的声音之间的500毫秒。我可以优化播放声音不知何故,也许,对于每一种声音创造一个专门的MediaPlayer的实例?

The problem is there is a delay ~500ms between an event and its sound. Can I optimize playing sound somehow, maybe, creating a dedicated MediaPlayer instances for every kind of sound?

问候,

推荐答案

使用SoundPool低延迟媒体播放,而不是的MediaPlayer

阅读全文

相关推荐

最新文章