Page 1 of 1
Pre-load sound(s)?
Posted: Sun Oct 09, 2011 12:46 am
by richardmac
I'm working on a program where the user touches a graphic and it plays a sound file. It works great on the iPad except for one thing - the very first time the user touches a graphic, there's a delay. It's not a bad delay, but it's enough to be annoying. And once the sound has been played, the next time they touch a graphic the sound is played instantly.
Is there a way to get rid of the delay on the first play of the sound?
Re: Pre-load sound(s)?
Posted: Sun Oct 09, 2011 1:01 am
by Dixie
richardmac,
Make yourself a short sound file that contains 'silence' and play it in your preOpenStack handler...then your first sound file will play without you noticing the lag... something like
Code: Select all
/*play some silence... seems to get rid of lag when everything first fires up */
play specialFolderPath("engine") & "/silence.mp3"
be well
Dixie
Re: Pre-load sound(s)?
Posted: Sun Oct 09, 2011 3:36 am
by richardmac
Nice! I will definitely try that. Thanks!
Re: Pre-load sound(s)?
Posted: Thu Jan 05, 2012 12:03 am
by teacherguy
I am experiencing this problem the first time a sound is used within a script...even if the same sound was used already in another script.

Re: Pre-load sound(s)?
Posted: Sat Jan 07, 2012 5:47 pm
by richardmac
Here's a trick that I've ended up using - use the iPhone native sound player. Like this:
Code: Select all
-- preload first sound
put specialFolderPath("engine") & slash & "sounds/C_2" & ".aif" into daSound
iPhoneSetSoundChannelVolume "Ch1","0"
iPhonePlaySoundOnChannel daSound, "Ch1","now"
-- then when you want to play the sound, raise the volume back up and play it
iPhoneSetSoundChannelVolume "Ch1","100"
put specialFolderPath("engine") & slash & "sounds/C_2" & ".aif" into daSound
iPhonePlaySoundOnChannel daSound, "Ch1","now"
This allows the sound to be played instantly without delay. The other nice thing about using iPHonePlaySoundOnChannel is that you can set up practically as many different channels as you want, so that sounds can play at the same time. VERY cool feature.
Re: Pre-load sound(s)?
Posted: Sat Jan 07, 2012 6:33 pm
by teacherguy
I can use that workaround in desktop applications?
Re: Pre-load sound(s)?
Posted: Sat Jan 07, 2012 9:09 pm
by richardmac
teacherguy wrote:I can use that workaround in desktop applications?
No, sorry - only works on the iOS. You might want to try Dixie's idea, for a regular app.
Re: Pre-load sound(s)?
Posted: Fri Jul 13, 2012 11:36 pm
by Randy Hengst
richardmac... just made use of your pre-load sound trick on iOS.... BIG difference. Thanks much for sharing it!
be well,
randy hengst
Re: Pre-load sound(s)?
Posted: Sat Jul 14, 2012 10:45 am
by Klaus
teacherguy wrote:I can use that workaround in desktop applications?
Sure you can (with another syntax and a "player" object of course), done this before, works great!
Best
Klaus