Solved

sndPlaySound API

Posted on 2000-04-11
9
666 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 28

Expert Comment

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 48
VB6 - Convert HH:MM into Decimal 8 56
How to Add / Edit Windows Menu 4 61
which modules are active in VB6 project? 6 12
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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

778 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