Can you quantify the lag? How much is it lagging? Lately I've been seeing my footstep sounds, which are individually triggered right and left steps, take 2-50ms to trigger for some reason. I'm not sure if it has something to do with the way the OGG is encoded, but I feel like it could. Perhaps the SoundPool author would like to chime in and give us some hints?
On Dec 18, 3:45 am, rukiman <ruksh...@optushome.com.au> wrote: > I am using the SoundPool as follows: > > Caching my sounds: > // load sound effects > soundPool = new SoundPool(2, > AudioManager.STREAM_MUSIC, 0); > soundPoolMap = new HashMap<Integer, Integer>(); > AssetFileDescriptor afd; > try { > afd = > context.getAssets().openFd("sounds/piecemove.ogg"); > soundPoolMap.put(SOUND_PIECEMOVE, > soundPool.load(afd, 1)); > > afd = > context.getAssets().openFd("sounds/piecestop.ogg"); > soundPoolMap.put(SOUND_PIECESTOP, > soundPool.load(afd, 1)); > > afd = > context.getAssets().openFd("sounds/pieceattack.ogg"); > soundPoolMap.put(SOUND_PIECEATTACK, > soundPool.load(afd, 1)); > > afd = > context.getAssets().openFd("sounds/pieceselect.ogg"); > soundPoolMap.put(SOUND_PIECESELECT, > soundPool.load(afd, 1)); > > afd = > context.getAssets().openFd("sounds/selection.ogg"); > soundPoolMap.put(SOUND_MENUSELECTION, > soundPool.load(afd, 1)); > > afd = > context.getAssets().openFd("sounds/pageturn.ogg"); > soundPoolMap.put(SOUND_PAGETURN, > soundPool.load(afd, 1)); > } catch (IOException e) { > e.printStackTrace(); > } > > Function to play sounds: > > public static int playSound(Context context, int sound) { > > AudioManager mgr = (AudioManager) context > .getSystemService(Context.AUDIO_SERVICE); > float streamVolumeCurrent = mgr > .getStreamVolume(AudioManager.STREAM_MUSIC); > float streamVolumeMax = mgr > > .getStreamMaxVolume(AudioManager.STREAM_MUSIC); > float volume = streamVolumeCurrent / streamVolumeMax; > /* Play the sound with the correct volume */ > return soundPool > .play(soundPoolMap.get(sound), volume, > volume, 1, 0, 1f); > } > > Playing a sound effect i.e when button is clicked: > > Resources.playSound(context, Resources.SOUND_PIECESELECT); > > However as I said the sound is lagging. What can I do to improve this? > All my sounds are OGG file format. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en