LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if a sound is playing before playing another?

Solved!
Go to solution

I'm sure that's true but it's not very helpful to just tell me it's too complicated. I don't know another way to do this; I'm just starting to learn about parallel loops today and I can see, as you mentioned in a previous comment, that parallel loops are a better way to organize when the sound is triggered to play. You had mentioned before just using a delay or something to make sure that loop only tried to play the sound again once the previous playback was finished. However, I see at least two issues with this idea; first, I have to find the exact length of any sound file I decide to use, which is kind of annoying. Second, if I want to be able to stop the sound partway through the sound execution, I need the loop to not be blocked by a delay function.

 

Again, I agree that this is probably too complicated but the knowledge I have so far doesn't seem to present a better way to do it. If you can see a simpler, cleaner way that doesn't change how that previous solution works I'm eager to fix the bad code I've got here (I'm not a fan of the crazy case structures either, I'm sure there are better ways but I'm still very new to this).

 

Thanks for helping, this forum has been a pretty awesome source of help while I'm new to LabVIEW

0 Kudos
Message 11 of 12
(492 Views)
Solution
Accepted by topic author Tarnarmour

Since the sound is so short, I would just go with a timeout of -1.

 

altenbach_0-1601683909415.png

 

The reason you are locking up sometimes is that stopping the sound does not release the resources, so if you continue to play new instances of the sound file, you are corrupting internal data structures. You need to read the help!!!

 

In your code, all you need to do is add a clear after each stop. A much simpler version is the attached (Version 1C):

 

altenbach_2-1601684427796.png

 

 

 

Another option would be to open the file before the loop and just start and stop it, clearing at the end. (version 1D) (small glitch is that the sound plays for a brief moment when the program is started. Probably no big deal).

 

altenbach_3-1601684782936.png

 

 

 

Download All
0 Kudos
Message 12 of 12
(482 Views)