Solved

PLAY WAV CODE IS NOT WORKING:

Posted on 2003-12-05
12
880 Views
Last Modified: 2013-12-25
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.

0
Comment
Question by:neonlights
  • 6
  • 5
12 Comments
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9883979
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
 

Author Comment

by:neonlights
ID: 9884066
Hi Rajesh,

Thanks for your message.

I am still getting RtnVal = 0

Not playing...

Do you know why?

Thanks
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9884086
just tried it, works fine on my system...
0
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 125 total points
ID: 9884128
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
 

Author Comment

by:neonlights
ID: 9884188
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
 

Author Comment

by:neonlights
ID: 9884236
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:neonlights
ID: 9884286
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
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9884525
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
 

Author Comment

by:neonlights
ID: 9888471
Hi Rajesh,
what is the meaning of ASYNC, and SYNC
Thanks
Bye
 
How to code media player?
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9888564
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
 
LVL 1

Expert Comment

by:rinkydink
ID: 9891577
you can always embedd your .wav's via OLE
then to play the wav use (ex.) OLE1.Action=7
0
 

Author Comment

by:neonlights
ID: 9909326
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now