Test if sound is playing (Solved)

Hi Guys,

First time post. :slight_smile:

I have had Codea for about six months now, but haven’t really touched it until today. So far, it looks great!

I am just wondering if there’s a way to test if a sound is currently playing?

Thanks in advance :slight_smile:

Not as far as I know. You could always make it so every time a sound plays It sets a veritable to true for the amount of time the sound plays. Then check if that variable is true.

You could have a table of all the length of the sounds, then you have a timer that tests if the length of the sound has passed. Otherwise, no.
Edit: It’s not recommended, but you could use the music function instead with multiple channels. That way you can know for sure.

Yes.

function setup()
    mySound = sound("Game Sounds One:Dropzone")
end

function draw()
    print(mySound.playing)
end

Source: http://codea.io/talk/discussion/4827/sound-only-allows-one-track-at-a-time#Item_7

Hi SkyTheCoder,

I did see these functions (which happens to be the same link you provided). These are apparently new from what I gather.

But, couldn’t find reference to them in the in-built manual.

The thing that confused me if the lack of .play in the example (in the link). Or does .playing actually start the playing of the sound (as we as indicate is the track is playing or not)?

Ok a test with your example SkyTheCoder. It appears the sound starts playing at the setup() part of your example.

This is fine, atleast I know how the program handles it now. As soon as you call sound() the sound will play. :slight_smile:

I wasn’t to sure if mySound was just being defined for later use.

LUA is slightly different that I am used to, but seems to be pretty easy to pick up :slight_smile:

Thanks again for your help guys.

Looking forward to using Codea more. It seems like a pretty cool creation tool.