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,
source share