Waiting for Sound

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
punchcard
Posts: 19
Joined: Mon Sep 28, 2015 5:41 am
Location: New York, NY, USA

Waiting for Sound

Post by punchcard » Mon Oct 26, 2015 5:53 pm

I am implementing multiple image changes (like a looping slide show) while waiting for an audio clip to finish. Initially I was doing this loop while checking for "wait until the sound is done with messages". However, it is quite possible I am mistaken, I found that the program was sluggish and not responsive. So, I changed to the following code for 10 second duration loops for the image changes, frequently checking for the sound to be finished (rather than using "wait until the sound is done with messages"). Does this make sense or is there an easier way to implement code while waiting for audio, while being very responsive to touch commands?

Code: Select all

on waitForAudio 
   repeat with t=0 to 200 
      wait 0.05 second with messages
      if the sound = "done" then exit repeat
   end repeat
end waitForAudio

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Waiting for Sound

Post by Klaus » Mon Oct 26, 2015 6:18 pm

punchcard wrote:...while being very responsive to touch commands?
Is this for mobile?

If yes, please ALWAYS note this fact, since that is a different world than the desktop stuff! 8)
And we even habe dedicated forums for mobile development.

punchcard
Posts: 19
Joined: Mon Sep 28, 2015 5:41 am
Location: New York, NY, USA

Re: Waiting for Sound

Post by punchcard » Mon Oct 26, 2015 6:43 pm

Sorry, yes, it is for mobile...

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Waiting for Sound

Post by Simon » Mon Oct 26, 2015 6:56 pm

Hi punchcard,
I'd use soundFinishedOnChannel with mobilePlaySoundOnChannel.
Then use your image swap if it changes

Code: Select all

local tSound
on soundFinishedOnChannel pChannel, pSound
   put false into tSound
end soundFinishedOnChannel

if tSound = true then
---do your image swapping
end if
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

punchcard
Posts: 19
Joined: Mon Sep 28, 2015 5:41 am
Location: New York, NY, USA

Re: Waiting for Sound

Post by punchcard » Tue Oct 27, 2015 2:22 pm

Thank you, Simon! I have tried mobilePlaySoundOnChannel, but, I believe I had trouble due to needing to also run a video(with audio) at the same time. Although I have only tested on an iOS simulator, I am able to do "play" audio while also having a video(with audio) play audio with my current code. Do you know if mobilePlaySoundOnChannel would possibly work with a concurrent video(with audio)?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”