LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wav Player Problem

Hi I'm having problems with this wav player I made BASED on labviews examples. Its suppose to play a file immediately when I enter a correct wav file name in the string. But whenever I run and press GO it keeps asking for the file then it plays it. Thanks to anyone who helps. 

Message 1 of 3
(2,376 Views)

Well, your program has numerous programming issues. The code is doing exactly what you told it to do. The File Dialog VI is always being called when you press the Go button - you have nothing to prevent it from running if the user entered a valid file. If the user enters a valid file then you do not want to run the File Dialog. A simple case structure will work for this.

 

However, you have other issues:

  • Using a string control for a filepath. Bad. Use a file path control.
  • The logic you are performing against the filename should be an OR function, not a NOR. That should be used to drive the case structure.
  • Instead of using the sound playing VI that you are using use, the "Play Sound File" that's in the sound functions palette. That one has a path input so you do not need to mess around with strings.
  • If you press the Stop button nothing will happen - the VI will not stop. Why? Because the event structure is waiting for an event, and the only event it's listening to is the change in value of the Go button. You should add an event for a value change for the Stop, put the Stop button terminal inside the case, and connect the Stop terminal to the while loop conditional through the event structure via a tunnel. You do not need to wire a value for the other event cases.
  • If you keep the sound playing outside then you need to make sure you do not play the sound if you're trying to stop the VI. One solution is to put the sound playing inside the event case for the Go button. Of course, the consequence of this is that you won't be able to stop the VI until the sound stops playing. Another is to put a case structure around the sound playing so that it plays as long as you're not trying to stop the VI (i.e., the Boolean wire is not true). I do not know what the final intent of this VI is, so I cannot tell you which solution is better.
0 Kudos
Message 2 of 3
(2,366 Views)

I leave an example that can provide

Message 3 of 3
(2,312 Views)