Sound in .net?

One of the flags for PlaySound is a flag that allows asynchronous sounds. Look that up somewhere.

Actually, I just found a class that has it. Not sure who wrote this, because they didnt comment in their name, but it wasnt me, so dont give me any credit.
Code:
Public Class CSound
    CALL THIS CLASS THUS:
    Dim SoundInst As New CSound
    SoundInst.PlaySoundFile("C:\Your\File\Here.wav")

    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal Name _
       As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
     name specifies the sound file when the SND_FILENAME flag is set.
     hmod specifies an executable file handle.
     hmod must be Nothing if the SND_RESOURCE flag is not set.
     flags specifies which flags are set. 

     The PlaySound documentation lists all valid flags.
    Public Const SND_SYNC = &H0           play synchronously
    Public Const SND_ASYNC = &H1          play asynchronously
    Public Const SND_FILENAME = &H20000   name is file name
    Public Const SND_RESOURCE = &H40004   name is resource name or atom

    Public Sub PlaySoundFile(ByVal filename As String)
         Plays a sound from filename.
        PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)
    End Sub
End Class
 
Actually the SND_ASYNC flag is for asynchronous processing, not asynchronous sounds.
Without the ASYNC flag, the code pauses on the PlaySound call until the sound is finished, while the ASYNC version will continue execution while the sound plays.

While you could get two sounds to play with PlaySound and mciSendString, your best bet is DirectSound, where you can declare multiple sound buffers. :)
 
Is there also a way to check if the sound is still playing ? Because I have a timer which constantly plays a sound, but the first one needs to be finished first :)

Thanks
Antoine
 
If you pass the SND_NOSTOP flag, the sound will not play if another sound is already playing.
Private Const SND_NOSTOP = &H10 dont stop any currently playing sound
 
Thanks !

I now use this line

Code:
        PlaySound(&H0, Nothing, SND_ASYNC)

To stop the sound, the sound stops, I only get a windows sound behind it :( is it also possible NOT to have this sound ?

Grtz,
Antoine
 
You need to pass the SND_PURGE flag to stop the sound thats currently playing.

Private Const SND_PURGE = &H40 purge non-static events for task

Or, you can do

Private Const SND_NODEFAULT = &H2 silence not default, if sound not found

Though this is better suited for if you are actually putting in a file as the filename argument. :)
 
Back
Top