PLAY WAV CODE IS NOT WORKING:

Where is my problem?

Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_SYNC = &H0


Public Function PlaySound(fPath As String, Optional Sync As Boolean = True) As Boolean
    Dim RtnVal As Long
    RtnVal = sndPlaySound(fPath, IIf(Sync, SND_SYNC, SND_ASYNC))
    MsgBox RtnVal
End Function


                filename = App.Path & "\LetItSnow.wav"
                MsgBox filename
                PlaySound filename

When I run this code: filename is good (msgbox)
and second msgbox = 0
So, it is not playing

WHY?
file is correct.

neonlightsAsked:
Who is Participating?
 
R_RajeshCommented:
are you you able to hear sound form other apps

try this:
make sure you change the path to the wave file

Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2

Private Sub Form_Load()
ret& = waveOutGetNumDevs
If ret& > 0 Then
ret1& = sndPlaySound("C:\Rajesh\alarm.wav", &H1 Or &H2)
Else
MsgBox "no waveout devices detected"
End If
End Sub
0
 
R_RajeshCommented:
Hi neonlights,

pass the path byval

Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_SYNC = &H0

Public Function PlaySound(ByVal fPath As String, Optional Sync As Boolean = True) As Boolean
Dim RtnVal As Long
RtnVal = sndPlaySound(fPath, IIf(Sync, SND_SYNC, SND_ASYNC))
MsgBox RtnVal
End Function

Private Sub Form_Load()
FileName = "C:\Rajesh\alarm.wav"
MsgBox FileName
PlaySound FileName
End Sub


Cheers!

Rajesh
0
 
neonlightsAuthor Commented:
Hi Rajesh,

Thanks for your message.

I am still getting RtnVal = 0

Not playing...

Do you know why?

Thanks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
R_RajeshCommented:
just tried it, works fine on my system...
0
 
neonlightsAuthor Commented:
I found the problem Rajesh.

My sound card was not working. It is working now.
The problem is that How do I stop the play and how do I know if the music stop playing....

looks like you have lots of knowledge in this matter. I also posted a question about this...check it out and reply to me please...that question is for 500 points..

Thanks Rajesh,
0
 
neonlightsAuthor Commented:
Hi Rajesh,

I was checking one of the question:
Question to check if the music still playing:
the answer was:

Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
Public Declare Function PlayWAV Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

To find out if the sound is still playing, call the function using SND_NOSTOP parameter instead of SND_ASYNC:

lRet = sndPlaySound filename, SND_NOSTOP

what is filename stand for here?
0
 
neonlightsAuthor Commented:
Thanks Rajesh,

here is my points. Please check my other question I posted about playing music, and finding when it stopped...My question has all the details...thanks

here is my copy of my question but, you can view it:
Title: PLAY MUSIC USING VB: URGENT 500 POINTS: NEED CODE:PLEASE - URGENT
Points: 500

Hi everyone:

What I would like to do is:

I created a phone system.

When the phone( I have 3 lines) are ringing, I would like to pick up the phone and play music. I know how to play(hardware). All I am looking for is the VB technique to do it.

So, let's say, line 1, line2, and line 3 are ringing.

I would like to pick up line1 and play music, and put the line on hold, and then pick up the line 2 and play music, and put it hold, and so on.( do not worry about the procedure involving put the line on hold - only play music)

My idea is:
1)There will be a tmr running every minute:
2)In my system, there are 2 lists - one contains - ringing lines, and other lines contains hold lines.  Tmr will check if any thing in the Ringing list. If it is,
3)  Tmr will be off, pick up that line.
4) Play music.
5)Once the music is stopped playing, then I will put the line on hold
6) Then I will go on to the next line.
7) Until there is no line in the ringing list.
8) Tmr will be on again.

I want to makesure that I won't interupt my playing for one line for another one.

I would like to play wav file. Is it a good idea. I would like to play using Winamp, I think it is not bad player..Is it a good choice?

I would like to have code..Only for the Tmr Function.
I know how to handles the lines ( put it on hold, pick up).
ONLY PLAY MUSIC AND WAIT UNTIL MUSIC IS STOPED PLAYED AND THEN MOVE ONTO A NEXT LINE.

Thanking you in advance.
0
 
R_RajeshCommented:
hi  neonlights,

sorry it took so long to answer, i just reached home.
looking at your questio though i would suggest you use a mediaplayer control. it can be manupilated easily and getting its palystate, starting, stopping and other such things can be easily accomplished

and thanks for the grade

:)
0
 
neonlightsAuthor Commented:
Hi Rajesh,
what is the meaning of ASYNC, and SYNC
Thanks
Bye
 
How to code media player?
0
 
R_RajeshCommented:
Hi neonlights,

calling the sndplaysound function with the async parameter makes the function return immediately after beginning the sound whereas using the sync parameter causes the function to return only after palying the entire sound.

try this, since we are calling the function using the SND_ASYNC paramenter the function returns immediately and after the sleep function which pauses the code for 2 seconds, the sound is cut off ( by calling the funciton with no parameter sndPlaySound(0, 0) ).

if we had used SND_ASYNC parameter the sound wouldn't have cut off after 2 seconds since the function wouldn't release control until the whole sound has played



Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const SND_ASYNC = &H1
Private Const SND_SYNC = &H0

Public Function PlaySound(ByVal fPath As String, Optional Sync As Boolean = True) As Boolean
Dim RtnVal As Long
RtnVal = sndPlaySound(fPath, SND_ASYNC)
Sleep (2000)
RtnVal = sndPlaySound(0, 0)
Unload Me
End Function

Private Sub Form_Load()
FileName = "C:\Rajesh\alarm.wav"
PlaySound FileName
End Sub
0
 
rinkydinkCommented:
you can always embedd your .wav's via OLE
then to play the wav use (ex.) OLE1.Action=7
0
 
neonlightsAuthor Commented:
Thanks Rajesh. That is what I did.

function X()
;
;
RtnVal = sndPlaySound(fPath, SND_ASYNC)
function Y - function Y did not call until whole song is finished. That is exactly I was looking for. But, I did not try your way.
end Function

Hi rinkydink,
Can not use OLE, since I will  have tons of wav file...It will take lots of memory...I think ...am I?

Thanks////
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.