Pre-load sound(s)?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Pre-load sound(s)?

Post by richardmac » Sun Oct 09, 2011 12:46 am

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?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Pre-load sound(s)?

Post by Dixie » Sun Oct 09, 2011 1:01 am

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

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: Pre-load sound(s)?

Post by richardmac » Sun Oct 09, 2011 3:36 am

Nice! I will definitely try that. Thanks!

teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Re: Pre-load sound(s)?

Post by teacherguy » Thu Jan 05, 2012 12:03 am

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. :cry:

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: Pre-load sound(s)?

Post by richardmac » Sat Jan 07, 2012 5:47 pm

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.

teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Re: Pre-load sound(s)?

Post by teacherguy » Sat Jan 07, 2012 6:33 pm

I can use that workaround in desktop applications?

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: Pre-load sound(s)?

Post by richardmac » Sat Jan 07, 2012 9:09 pm

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.

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 157
Joined: Thu Jun 29, 2006 4:16 pm

Re: Pre-load sound(s)?

Post by Randy Hengst » Fri Jul 13, 2012 11:36 pm

richardmac... just made use of your pre-load sound trick on iOS.... BIG difference. Thanks much for sharing it!

be well,
randy hengst

Klaus
Posts: 14183
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pre-load sound(s)?

Post by Klaus » Sat Jul 14, 2012 10:45 am

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! :D


Best

Klaus

Post Reply