Wavfile playing trubcated

B

Brett

I posted a similar Q a couple of weeks ago and Jacob Skaria pointed me to
MrExcel's site. I'm now using the code from there to play wavfiles, but the
problem hasn't changed. When I play a wavfile at the start of a procedure it
will (more often than not) only play the first tenth of a second (subsequent
statements of
ANY kind seem to terminate it). Other times (in the SAME subroutine, and
without code changes) it will play completely. If I play the Wavfile at the
end of a procedure then it always plays all of it.

I have (from MrExcel)

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal
lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_FILENAME = &H20000
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_MEMORY = &H4
Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10
Dim WAVFile As String

and then a series of:
Sub G02_WAV_CHIMES()
WAVFile = "C:\0. QUO VADIS\SOUNDS\chimes.wav"
Call sndPlaySound(WAVFile, SND_ASYNC Or SND_FILENAME)
End Sub

What can be causing this intermittent problem please?
Is there something that needs to be cleared (or whatever) before playing a
WAV? Brett
 
J

Jacob Skaria

Brett using the below code check the return value for cases which terminate..

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub G02_WAV_CHIMES()
returnvalue = sndPlaySound ("C:\0. QUO VADIS\SOUNDS\chimes.wav", 0)

End Sub

If this post helps click Yes
 
J

Jacob Skaria

Brett, here if the argument uFlags is 0 the function returns only once the
wav file is completely played and if set to 1 returns as soon as the wav file
is started. You set this to 0 for your requirement..

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub Macro()
sndPlaySound "D:\1.wav", 0
sndPlaySound "D:\2.wav", 0
sndPlaySound "D:\3.wav", 0
End Sub

In the code you posted below you can change to as below which will do the
same..
Call sndPlaySound(WAVFile, SND_SYNC)

If this post helps click Yes
 
B

Brett

Hi Jacob, thanks for replying. I tried that on a few and they all return 1,
but that was just playing them stand alone. As I understand things, if I
leave the second parameter as 0 then it will play syncronously and therefore
there is no point in playing it that way within the larger macro (where it
truncates) because the larger macro will wait until the wav is finished
before continuing.

In fact I just tested it within the larger macro and it does just that
(still returns 1 as well). Actually I'm not really sure what you're asking me
to do here!. Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top