Napivo1972 Posted January 17, 2005 Posted January 17, 2005 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. Quote
coldfusion244 Posted January 17, 2005 Posted January 17, 2005 I would suggest using DirectSound. You can fade channels, pan left/right/front/back/etc. It's part of the directx SDK i believe. Quote -Sean
sgt_pinky Posted January 17, 2005 Posted January 17, 2005 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 Quote
Leaders Iceplug Posted January 18, 2005 Leaders Posted January 18, 2005 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. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
sgt_pinky Posted January 19, 2005 Posted January 19, 2005 Cheers. Sorry for that misinformation ;) Quote
Antoine Posted February 9, 2005 Posted February 9, 2005 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 Quote
Leaders Iceplug Posted February 9, 2005 Leaders Posted February 9, 2005 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 Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Antoine Posted February 10, 2005 Posted February 10, 2005 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 Quote
Leaders Iceplug Posted February 11, 2005 Leaders Posted February 11, 2005 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. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.