Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Play Multiple Sounds in Series not Parallel

Author
Message
OpusTheFowl
8
Years of Service
User Offline
Joined: 9th Feb 2016
Location:
Posted: 2nd Dec 2016 00:09
Hi there,

Just wondering what common suggestion is for this situation.

Let's say I generate 6 random numbers from 1 to 100. I also have a individual WAV files for each number. So now I want to play those six WAV files one after the other but this will just play them all at once:
PlaySound(1)
PlaySound(2)
PlaySound(3)
...

Ian't there a way to buffer sounds to play in the near future? For example, if I wanted a one second pause between the WAVs (or a play in X seconds):
PlaySound(1)
Wait(1000)
PlaySound(2)
Wait(2000)
PlaySound(3)
Wait(3000)
...
This would play the first sound and in 1 second play the second sound and in 3 seconds the third...etc...


Sleep works perfectly if you don't mine the program halting but in my case, I can't have that. I'm guessing timers are the answer but I can't seem to think of a simple/elegant way to do that.

What are the suggestions for this situation?

Thanks in advance!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Dec 2016 10:49 Edited at: 2nd Dec 2016 10:51
Try this approach...

Create an array to save the sound references
When a sound is playing you can get a reference to the sound instance, so you can check if it is still playing
When it stops, play the next one
Keep a reference to the current sound playing so you can move it on, loop back to sound 1 etc.

Sample code below, untested. This should play each sound in turn then loop back to the first. The check is done in the main loop, so everything else in your game keeps on moving

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
damothegreat
User Banned
Posted: 2nd Dec 2016 11:51
@batvink- that should do it
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
OpusTheFowl
8
Years of Service
User Offline
Joined: 9th Feb 2016
Location:
Posted: 2nd Dec 2016 14:34
Thanks BatVink,

A few hours after my post I figured it out. I used variables but I like your array idea better so I will switch to that as it's much more elegant.

Thanks!

Login to post a reply

Server time is: 2024-04-18 08:04:17
Your offset time is: 2024-04-18 08:04:17