Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I know it has been asked already and I even found the API way of sending sounds but that�s not going to cut it this time I am afraid.

 

Private Declare Function PlaySound Lib "winmm.dll" (ByVal fileName As String, ByVal hmod As IntPtr, ByVal flags As PlaySoundFlags) As Integer

 

This plays only one wav at the same time and stopt the previous one.

 

I am looking for a multi channel Wav and .MP3 player to integrate in my space invaders game. I�ll probably have to go and look into direct sound but can anyone help me get on my way.

 

Furthermore I want to load the Wav files from disk (not the resources) into a cache and play them from there.

Posted

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 wasn't me, so don't give me any credit.

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

  • Leaders
Posted

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. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • 3 weeks later...
Posted

Is there also a way to check if the sound is still playing ? Because I have a timer which constantly play's a sound, but the first one needs to be finished first :)

 

Thanks

Antoine

  • Leaders
Posted

If you pass the SND_NOSTOP flag, the sound will not play if another sound is already playing.

Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Thanks !

 

I now use this line

 

       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

  • Leaders
Posted

You need to pass the SND_PURGE flag to stop the sound that's 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. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...