-
I know how to play WAV files from here.. But how can I play the MIDI files too?
Thank you in advance for your help.
*** This is what I am using rightnow for the WAVES ***
Public Sub PlayWavResource(pintResourceID As Integer)
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1 ' Play asynchronously
Private Const SND_NODEFAULT = &H2 ' Don't use default sound
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
'Usage: PlayWavResource ResourceID
'Example: Call PlayWavResource(101)
Dim retVal As Long
Dim SoundBuffer As String
SoundBuffer = StrConv(LoadResData(pintResourceID, "CUSTOM"), vbUnicode)
retVal = sndplaysound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
End Sub
-
Sure thing. You can use this similar routine to play MIDI from resource:
Code:
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
Public Function PlayResourceMIDI(pintResourceID As Integer)
Dim lRetVal As Long
Dim strBuffer As String
strBuffer = StrConv(LoadResData(pintResourceID, "CUSTOM"), vbUnicode)
lRetVal = mciSendString("open " & strBuffer & " type sequencer Alias midifile", 0&, 0, 0)
lRetVal = mciSendString("play midifile wait", 0&, 0, 0)
lRetVal = mciSendString("close midifile", 0&, 0, 0)
End Function
Usage: PlayResourceMIDI ResourceID
Samle: Call PlayResourceMIDI(101)
-
I gave it a try but it does not play. What am I doing wrong? I have another routine that I have used and it will play them for me. But I cannot access a Midi from the Resource.
I have used:
Dim SafeFile As String
SafeFile$ = Dir(MIDIFile$)
If SafeFile$ <> "" Then
Call mciSendString("play " & MIDIFile$, 0&, 0, 0)
End If
-
Did you copy the declaration as well?? I've tested it many times and it works just fine.
-
i dont understand how u make the wave sounds play with a resouce file where do u tell the code the destination of the file in the res file
i use 2 sound modules in the program i make
one:
Option Explicit
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpsz As String, ByVal hModule As Long, ByVal z As Long) As Long
A = PlaySound("D:\James\Yr 7 game\Sounds\Start.wav", 0, 1) 'plays a sound when the form is loaded
i use this moduel becouse it is simple
i ahve another module that makes sounds repeat
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_FILENAME = &H20000 ' name is a file name
Private Const SND_LOOP = &H8 ' loop the sound until next
sndPlaySoundPlaySound "D:\James\Yr 7 game\Sounds\Theme.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC Or SND_LOOP 'it will play this sound
can i still play sounds with those modules or so they can repeat and etc
HELP please
thanks alot
Trav