LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop WAV sound playback via sndPlaySoundA

Hello,

I've sucessfully integrated the "sndPlaySoundA" rountine from the winmm.dll library to play a sound asynchrounously. I would like to have the option of stopping the sound, but cannot seem to find a way to do so. Web queries on the function have say that calling sndPlaySoundA with a null string for the filename and a 0 for the integer arguement should stop all sounds from playing. I've tried this by hooking up a null string constant to the DLL, and calling the routine when I'd like the sound to stop. Unfortunately, it's not working and the sound keeps on playing.

Has anyone seen this before, or have any suggestions?

Thanks
-Ted
0 Kudos
Message 1 of 6
(5,124 Views)
Ted,

Unfortunately, I have not used that specific Windows DLL previously, so I am not sure how you could get that sound to stop. Is this the only functionality of the library that you are using? I ask because I can suggest you bypass the DLL altogether and use the Sound VIs in LabVIEW. If you go to the block diagram and view the functions pallet, select Programming >> Graphics and Sound >> Sound >> Output. These VIs will hopefully allow you to play the desired sound file without having to worry about the DLL specifics. The link below details how these VIs can be used to play a sound. I would also suggest taking a look in the LabVIEW Example Finder to locate an example that would help with your application. I hope this information is useful for you!

Mike

Using the Sound Output VIs in LabVIEW:
http://digital.ni.com/public.nsf/websearch/1BE60DBBFA22ACC186256DFB000B8464?OpenDocument
0 Kudos
Message 2 of 6
(5,112 Views)
Hi Mike,

Thanks for the info. (I found the win DLL interface functions in the examples folder). It seems the VIs you reccomend call NI specific DLLs.

This is what I'm trying to accomplish:

Start playing a sound. The sound should end when either:
#1: the end of the wav file is reached, or
#2: the user hits a button.

If there was some documentation on the internal DLL functions for the sound VIs, I could probably get there. Seems like a better way to go than the approach I was taking since the Labview functions presumably are platform independent.

Thanks
-Ted

Message Edited by tpascaru on 10-06-2006 01:15 PM

0 Kudos
Message 3 of 6
(5,110 Views)
Ted,

If you use the Sound Output Start vi to start your playing your wave file, it will stop when the end of the file is reached.  You'll want to wire up a Sound Output Clear at the end of it to ensure the reference to the wave file is closed.

If you'd like to stop the file when the user hits a button, you'll a while loop immediately after the start vi which continually polls a stop button.  If the stop button is pressed, simply wire in a Sound Output Stop vi.  Make sure you put in a wait in the while loop.
TheDillo
0 Kudos
Message 4 of 6
(5,093 Views)

The Dillo's solution, on Labview 8.5.1 causes Sound Output Write.vi to "freeze" inside a call shared library node.

 

I've attached a screenshot - you can see the call shared library node has not exited and appears to be "stuck".

 

I have to force quit- LabVIEW.exe from task manager to recover.

 

 

Does anyone have an alternate way of stopping the VI?

0 Kudos
Message 5 of 6
(3,897 Views)

Hi AlexDubya,

 

Could you post your main and subVIs so that I could try to reproduce this?

 

Have a great day!

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 6 of 6
(3,868 Views)