Computer Science Canada

How to play midi files for my game

Author:  RaLz [ Thu Jun 10, 2004 4:59 pm ]
Post subject:  How to play midi files for my game

how do i do this i need to know how and quickly!!!!

Author:  Brightguy [ Thu Jun 10, 2004 9:40 pm ]
Post subject:  Re: How to play midi files for my game

Well there are two ways that I know of...
Using mciSendString, a list of commands can be found here.
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
Private lngMciErr As Long

Private Sub Form_Load()
    lngMciErr = mciSendString("open FILENAME type sequencer alias mid1", 0&, 0&, 0&)
    lngMciErr = mciSendString("play mid1", 0&, 0, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    lngMciErr = mciSendString("close mid1", 0&, 0&, 0&)
End Sub

Or you can just use the Microsoft Multimedia Control - add it to your project through the menu Project > Components...
code:
Private Sub Form_Load()
    MMControl1.Filename = FILENAME
    MMControl1.Command = "Open"
    MMControl1.Command = "Play"
End Sub

Private Sub Form_Unload(Cancel As Integer)
    MMControl1.Command = "Close"
End Sub
You can set MMControl1.Visible = False if you don't want to see the control on the form.


: