Solved

sndPlaySound API

Posted on 2000-04-11
9
668 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

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 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 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…
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…

756 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