Link to home
Start Free TrialLog in
Avatar of neonlights
neonlights

asked on

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.

Avatar of R_Rajesh
R_Rajesh

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
Avatar of neonlights

ASKER

Hi Rajesh,

Thanks for your message.

I am still getting RtnVal = 0

Not playing...

Do you know why?

Thanks
just tried it, works fine on my system...
ASKER CERTIFIED SOLUTION
Avatar of R_Rajesh
R_Rajesh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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,
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?
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.
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

:)
Hi Rajesh,
what is the meaning of ASYNC, and SYNC
Thanks
Bye
 
How to code media player?
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
you can always embedd your .wav's via OLE
then to play the wav use (ex.) OLE1.Action=7
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////