Solved

PLAY WAV CODE IS NOT WORKING:

Posted on 2003-12-05
12
876 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
Comment Utility
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
Comment Utility
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
Comment Utility
just tried it, works fine on my system...
0
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:neonlights
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
you can always embedd your .wav's via OLE
then to play the wav use (ex.) OLE1.Action=7
0
 

Author Comment

by:neonlights
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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