Android plays sounds after delay
android, audio
Solution
Use `SoundPool` for low-latency media playback, instead of `MediaPlayer`.
Problem
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) { } } ``` 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? Regards,