I am trying to build an algorithm for handling sounds in my project, but I am having difficulties conceptualising the sequence.
These are my requirements:
- sound playing should be some sort of "last in, last out", in a queue
- every sound should play to its end, without replacing the one currently playing and without being cut off
- sound firing could implying more then 1 sound in a row, to be played in the same input order
- the user should be able freely do other actions, without interrupting the playing sound and eventually starting other sounds to be put in the queue
In order to do this, I got together something like this (simplified from my real code):
Code: Select all
local sSoundIsPlaying = ""
On SoundPlay tSoundName
--get path to the sound(s) and put it(them) after tSouldList
-----
--tSoundList is now 1 or more lines, each with a (different) sound path
Send "SoundPlayLater tSoundList" to me in 0 seconds
end SoundPlay
on SoundPlayLater pSoundList
wait until not sSoundIsPlaying
put true into sSoundIsPlaying
put pSoundList into tNewSoundList
repeat until tNewSoundList is empty
put line 1 of tNewSoundList into tPath
play tPath
wait until the sound is "done" with messages
delete line 1 of tNewSoundList
end repeat
put false into sSoundIsPlaying
end SoundPlayLater
For Android I will have to use "mobilePlaySoundOnChannel" and "soundFinishedOnChannel", but I guess it will be more or less the same.
What I am having trouble to understand is if the command receiving a "send", handles each variable as a different instance of it or not.
Thanks
Trevix