Solved

sndPlaySound API

Posted on 2000-04-11
9
670 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

734 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