How can I play a number of sounds one after another? I would like to hear them one after one.
Something like:
function test()
PlayMySound("1.wav")
PlayMySound("2.wav")
PlayMySound("3.wav")
end
Of course when I just use PlaySound I will hear all of them at the same time.
I thought about using timers and checking if sound is playing in for example buffer 1 to play next one and setting the name of it in the variable but it won't work for more than 2 sounds. Forgive me my poor knowledge.
You should be able to use GetSoundStatus to see if a sound has finished playing and then move onto playing another one. I don't see why that would not work for more than two sounds.
function test()
PlayMySound("1.wav")
PlayMySound("2.wav")
PlayMySound("3.wav")
end
function PlayMySound(filename)
while GetSoundStatus(1) > 0 then
end
PlaySound (1, filename, false, 0, 0)
end
In this example test plays 3 files but in real example different function can play a sound. I'm not sure it that while loop won't hang my whole plugin?
require "wait"
function PlayOneSound (name)
while GetSoundStatus (1) > 0 do
wait.time (0.1)
end -- while
PlaySound (1, name)
end -- PlayOneSound
function soundTest ()
wait.make ( function ()
PlayOneSound ("1.wav")
PlayOneSound ("2.wav")
PlayOneSound ("3.wav")
end ) -- end of wait.make
end -- soundTest
soundTest ()
Using the "wait" module like this stops the client from hanging while it plays the sounds, potentially for quite a few seconds.
require "wait"
function PlayOneSound (name)
wait.make ( function ()
while GetSoundStatus (1) > 0 do
wait.time (0.1)
end -- while
PlaySound (1, name)
end ) -- end of wait.make
end -- PlayOneSound
PlayOneSound ("1.wav")
PlayOneSound ("2.wav")
PlayOneSound ("3.wav")
Now you can call PlayOneSound whenever you feel like it.