Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Preloading a sound

edited February 2012 in Questions Posts: 65

Hi. Quick one: I use this sound when a player loses a level, but its a long sound and the app pauses to load the sound the first time it's played:


Any way I can preload/precache this?



  • Posts: 2,820

    I think you can say var = sound() but I'm not sure. I'm not around my iPad. If not, you can try putting it in a function that returns it. Now I don't know. Sorry. I don't mean to confuse you of this doesn't work.

  • edited February 2012 Posts: 1,255

    My experience is that playing a long sound doesn't tend to slow performance -- but trying to play an overlapping sound does. That is, if you have a sound underway, and make another call to sound(), things can get choppy, particularly if multiple calls stack up. If you want a longer sound to play out as previewed and not cause delay, you may need a timer or flag to ensure it doesn't get called more than once.

    Sorry if this doesn't resolve your issue. Since sounds are synthesized and not loaded from file, I haven't had an issue with first-play time.

    I do notice about a half-second delay if I play the sound above, but it doesn't seem to play any faster if I delay a few seconds and play it again.

  • SimeonSimeon Admin Mod
    Posts: 5,613

    @peteroyle version 1.3.1 will offer a lot of control over sound caching, however for now I believe you can do the following to pre-cache a sound:

    -- Play sound once, at the start, with volume 0
    -- Subsequent plays should be cached
  • Posts: 384

    If your sounds are long, you may need to increase the soundBufferSize(), otherwise it will delay during the sound generation.

  • Thanks for the suggestions everyone. I used Simeon's trick and it's working fine now.

Sign In or Register to comment.