add isPlaying() to sound library
(I'm adding some items that came up in an e-mail discussion re: the Processing sound library.)
Read more about the discussion here: processing/processing#2684
@shiffman this was also for soundfiles, right?
Yes, the idea is to be able to determine if a sound is already playing without having to have your own boolean. This comes up a lot when play() is called in, say, a draw() loop.
void draw() {
if (!sound.isPlaying()) {
sound.play();
}
}
I'm not sure it's relevant for generated sound?
will be added with the next release. .play() is not supposed to be called in the draw loop at any times but it might be a good idea to have it.
If I may, it definitely a nice feature to have. It would also be worth implementing it in the Env class too.
Would be nice to have this indeed.
yes, i'll incorporate it. For now you can just set a variable to flag true or false to work around not having this.
Would be great to have this
indeed, +1 for this
Has this been implemented as working yet ? I notice the method exists but a simple println on the value while a file plays once just leaves it as 1 and it doesnt change to 0 when the audio has finished
@wirsing you said above:
.play() is not supposed to be called in the draw loop at any times but it might be a good idea to have it.
So, how would one, say, play a sound that isn't in setup or connected to a key press or mouse press? Like, say I wanted to play a sound when the mouse got to the edge of the sketch and not have it trigger on every cycle of draw?
I tried putting .play() in it's own function, which didn't work.
I've got a bunch of code written to check how long it's been since a file was triggered, if that's longer than the duration of the file, etc. But it just feels clunky.
Also @ashleyjamesbrown just tested with 1.3.2 and got the same results you did.