Page 1 of 1

Waiting for Sound

Posted: Mon Oct 26, 2015 5:53 pm
by punchcard
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

Re: Waiting for Sound

Posted: Mon Oct 26, 2015 6:18 pm
by Klaus
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.

Re: Waiting for Sound

Posted: Mon Oct 26, 2015 6:43 pm
by punchcard
Sorry, yes, it is for mobile...

Re: Waiting for Sound

Posted: Mon Oct 26, 2015 6:56 pm
by Simon
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

Re: Waiting for Sound

Posted: Tue Oct 27, 2015 2:22 pm
by punchcard
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)?