I know you can load wav, ico, cur, bmp, avi, txt and use them in a resource file. Does anyone know how to load and play Midi files from a resource file?
Printable View
I know you can load wav, ico, cur, bmp, avi, txt and use them in a resource file. Does anyone know how to load and play Midi files from a resource file?
http://www.vbforums.com/showthread.p...sound+resource
That should get you started.
Hi Keithuk, I dont think you can load the midi data directly, think you have to temp save the info to disk when you want to play the midi.
I made a sample a long time ago for someone else at this forum.
hope that can get you going.
VB Code:
Private Sub StartSong() Dim ret As Integer Dim sBuffer As String 'sSong contains the name of the temp. file sSong = App.Path & "\miditmp.mid" 'if it exists kill it If Dir(sSong) <> "" Then Kill sSong 'get the file from the resource file 'and save it to disk sBuffer = StrConv(LoadResData("TO_TOWN", "MDI"), vbUnicode) Open sSong For Output As #1 Print #1, sBuffer Close #1 'start playing the song ret = mciSendString("open " & Chr(34) & sSong & Chr(34) & " type sequencer alias to_town", 0&, 0, 0) ret = mciSendString("play to_town", 0&, 0, 0) End Sub
u might want this too :
VB Code:
Private Sub StopSong() Dim ret As Integer 'stop playing the song ret = mciSendString("close to_town", 0&, 0, 0) 'delete the temp. midi file If Dir(sSong) <> "" Then Kill sSong End Sub
Thanks Peet your code works a treat.
Ok, I'm trying to get this code to work and im coming across a few problems that I don't understand.
I've loaded a midi into a resource file, it says that It's type is "CUSTOM" and It's ID is 101. So I took the code and replaced all instances of "TO_TOWN" with 101 and all instances of "MDI" with "CUSTOM". I'm not sure if that's what I was supposed to do or not.
I also need to know what "mciSendString" is. I just get a compile error. Thanks.
you need the MCI API. google it or search the forums.
Sorry, this will sound really dumb, but what exactly is an API?
Application Programming Interface.
It extracts information out of dll files normally.
e.g.
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
See if you have "Program Files\Microsoft Visual Studio\Common\Tools\Winapi\APILOAD.EXE" installed.