Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sndPlaySound API

Posted on 2000-04-11
9
Medium Priority
?
678 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 450 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

722 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