Pre-load sound(s)?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 211
- Joined: Sun Oct 24, 2010 12:13 am
Pre-load sound(s)?
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?
Is there a way to get rid of the delay on the first play of the sound?
Re: Pre-load sound(s)?
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
be well
Dixie
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"
Dixie
-
- Livecode Opensource Backer
- Posts: 211
- Joined: Sun Oct 24, 2010 12:13 am
Re: Pre-load sound(s)?
Nice! I will definitely try that. Thanks!
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Pre-load sound(s)?
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. 

-
- Livecode Opensource Backer
- Posts: 211
- Joined: Sun Oct 24, 2010 12:13 am
Re: Pre-load sound(s)?
Here's a trick that I've ended up using - use the iPhone native sound player. Like this:
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.
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"
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Pre-load sound(s)?
I can use that workaround in desktop applications?
-
- Livecode Opensource Backer
- Posts: 211
- Joined: Sun Oct 24, 2010 12:13 am
Re: Pre-load sound(s)?
No, sorry - only works on the iOS. You might want to try Dixie's idea, for a regular app.teacherguy wrote:I can use that workaround in desktop applications?
-
- VIP Livecode Opensource Backer
- Posts: 157
- Joined: Thu Jun 29, 2006 4:16 pm
Re: Pre-load sound(s)?
richardmac... just made use of your pre-load sound trick on iOS.... BIG difference. Thanks much for sharing it!
be well,
randy hengst
be well,
randy hengst
Re: Pre-load sound(s)?
Sure you can (with another syntax and a "player" object of course), done this before, works great!teacherguy wrote:I can use that workaround in desktop applications?

Best
Klaus