Solved

sndPlaySound API

Posted on 2000-04-11
9
662 Views
Last Modified: 2012-05-04
Hi, I'm using the sndPlaySound api to play a wav file. The wave file plays O.K, however while it is playing, any other events that occur are ignored until the wave file is finished.  I've tried experimenting with the MMControl and although I can get it to play wave files, it has the same effect as the sndPlaySound api.

Maybe I'm going about it the wrong way, but could someone recommend a way to play a wav file and still be able to service other events at the same time.

Thanks,
GavinS
0
Comment
Question by:GavinS
9 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 150 total points
ID: 2706628
Public Const SND_ASYNC = &H1        


are you using this constant when you call the function??  e.g.,
sndPlaySound filename, SND_ASYNC Or SND_NODEFAULT
0
 

Author Comment

by:GavinS
ID: 2706686
Yes, I am using the SND_ASYNC const. Here is the code I've written to play the wav file......

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10

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

Public Sub Playwav(Wavefile As String)
    SoundName$ = Wavefile
    bayrak% = SND_ASYNC Or SND_NODEFAULT
    x% = sndPlaySound(SoundName$, bayrak)
End Sub
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2706702
Use 0 instead of 1 or vise versa I'm not sure one parameter of them lets you process other events and the other block the process until the wav finished.

sndPlaysound("test.wav", 0);
or
sndPlaySound("test.wav", 1);

Motaz
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2706714
hmmm what events does it seem to be stalling?
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.

 
LVL 14

Expert Comment

by:mcrider
ID: 2706723
Try this example instead...


Start a new project and put 4 command buttons on the form, then paste this code into the declarations section of the form (MODIFY THE SONG DECLARATION BEFORE RUNNING):

Private Declare Function mciSendString Lib "winmm.dll" Alias _
   "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
   lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
   hwndCallback As Long) As Long

' Modify the value of the constant "Song" with your path
      ' to whatevever wav you're going to play.
      Private Const Song As String = "D:\Windows\Sounds\Bathroom.wav"

Private Sub Command1_Click()
    Dim ret As Integer
     
    ' The following will open the waveaudio with the song
    ' file. wavefile is the device_id.
     
    ret = mciSendString( _
    "open " & Song & " type waveaudio alias wavefile", _
    0&, 0, 0)
     
    ' The notify tells the MCI command to return
    ' control to the application.
     
    ret = mciSendString("play wavefile notify", 0&, 0, 0)
End Sub
Private Sub Command2_Click()
    Dim ret As Integer
    ' Pause wave file and device
    ret = mciSendString("pause wavefile", 0&, 0, 0)
End Sub
Private Sub Command3_Click()
    Dim ret As Integer
    ' Pause resume file and device
    ret = mciSendString("resume wavefile", 0&, 0, 0)
End Sub
Private Sub Command4_Click()
    Dim ret As Integer
    ' Pause close file and device
    ret = mciSendString("close wavefile", 0&, 0, 0)
End Sub
Private Sub Form_Load()
Command1.Caption = "open/play"
Command2.Caption = "pause"
Command3.Caption = "resume"
Command4.Caption = "close"
End Sub


Cheers!®©
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2706733
try this:

Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
   (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
   
Private Const SW_SHOWNORMAL As Long = 1


Call RunShellExecute("Play", "c:\win\media\Notify.wav", 0&, 0&, SW_SHOWNORMAL)


0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2706743
sorry wrong declaration:

Public Sub RunShellExecute(sTopic As String, sFile As Variant, _
                           sParams As Variant, sDirectory As Variant, _
                           nShowCmd As Long)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2706762
scratch that idea...but i still dont see why its halting your program
0
 

Author Comment

by:GavinS
ID: 2709905
Hmmm, well I can't see what the difference is but I tried passing "3" directly to the sndPlaySound api instead of masking constant flags together and now its working.  Thanks,

Regards,
GavinS
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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now