LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sound file plays before I need it to

So I made a bingo challenge board and I set it up that whenever a bingo occurs a light illuminates with the word "bingo" on it. The game that this challenge board is for has a character that is known for saying "Bingo" during one of the levels so I found that file, converted it to a .wav and set it up to play whenever a bingo occurs. My only problem is that I got it to play, but it plays before the light. The order goes Bingo occurs > sound plays > light illuminates > game stops, I want it to go Bingo occurs > Light illuminates > sound plays > game stops but I cant figure out how to make the order switch. Here is a screenshot of the light and sound section of the code, Its a gigantic code so i figure a specialized screenshot would be more useful than the whole code with multiple subVIs and lots of craziness.

CaptureBingo.PNG

0 Kudos
Message 1 of 17
(2,448 Views)

There is nothing that controls whether the light is lit or the case structure executes first.

 

(Though I'm surprised a sound file playing would occur first.).

 

If you want to guarantee that the light executes first,wrap it in a single frame flat sequence and have the boolean wire go into and out of that flat sequence before going to the case structure.

 

While we don't want your whole VI, it would have been helpful to attach a simplified VI that replicates the issue you are having.

0 Kudos
Message 2 of 17
(2,435 Views)

You are a New Member, so you don't know that pictures of pieces of code are about as useful as my sending you 6 lines of my 1000-line Matlab code and saying "Why doesn't this work?".

 

Trust us, we've all see code much worse than yours.  We might be able to help you "make it better", but not if we don't see it.

 

Did you try the "experiment" of writing a little VI and making it play the sound when you push a button?  Do you start the entire process when you push the button, or do you do some preliminary stuff that might take time, and do the "Play" only when the button is pushed?  Have you run all of the Sound examples?  Have you read the Help for all of the Sound functions?

 

Post (all of) your code!

 

Bob Schor

0 Kudos
Message 3 of 17
(2,406 Views)

If the light really doesn't come on until AFTER the sound file plays, then somehow your VI is running in the UI thread.

 

In your main toplevel VI, go to File -> VI Properties -> Execution. What's the value for "Preferred Execution System"? If that's "User interface", set it to "Standard" or "Same as caller".

 

if that setting is already at "Standard" or "Same as caller" then post your code. Play Sound File should only halt the user interface when it's called from the UI thread.

0 Kudos
Message 4 of 17
(2,395 Views)

What's the purpose of the FOR loop?

 

0 Kudos
Message 5 of 17
(2,383 Views)

Also read the help and set the timeout to 0 (instead of 2!), this way it's not blocking code from proceeding.

0 Kudos
Message 6 of 17
(2,346 Views)

I got it to work, the 2 is so that it plays the full 2 seconds of the sound clip, otherwise you don't hear the whole thing

0 Kudos
Message 7 of 17
(2,334 Views)

So others with your problem can be helped in the future, please click "Mark as Solution" on whoever's post had the correct answer, and let us know what you did to fix things.

0 Kudos
Message 8 of 17
(2,330 Views)

I'm sorry, I will keep that in mind, I didn't feel like the rest was really important because it is literally just 25 control LEDs connected to 13 different 'and' or 'or' combinations and a switch.

0 Kudos
Message 9 of 17
(2,326 Views)

Um, it kind of just started working. I genuinely don't know what happened, and it definitely wasn't anyone's solution here. I just went back to it and worked on other parts of the code and next time I tried it, it worked how I wanted it to. I'm sorry if anyone else has this problem again because I really don't know how it worked.

0 Kudos
Message 10 of 17
(2,323 Views)