Android plays sounds after a delay

I need to play sounds in graphical interfaces like click buttons etc. To this end, I call the following code from a 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) { } } 

The problem is the delay of ~ 500 ms between the event and its sound. Can I somehow optimize the sound reproduction, perhaps creating dedicated MediaPlayer instances for each type of sound?

Hi,

+4
source share
2 answers

Use SoundPool for low latency playback instead of MediaPlayer .

+6
source

I see that this already has an accepted answer, but I would add that there is currently no complete solution: Android currently has a very large latency of sound. Devs is still waiting for a good solution.

This issue applies to NDK, but the issue is common:

http://code.google.com/p/android/issues/detail?id=3434

+4
source

All Articles