Plaing MIDI using API

Without using the MCI Control, how do i play a midi file using API declaration?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This microsot KB article will do what you want...

HOWTO: Play MIDI Files Using API Functions 


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mhdhallakAuthor Commented:
If you have read thier article...
The problem with it is that the application cannot do anything until the midi is over and I don't want it to be like that. I want the midi song to accompany the running of my application.

How do i do that?
The only API Declaration you need its

   Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

In order to open a midi file use

  mciSendString "open " & App.Path & "\musicfile.mid alias tune", vbNullString, 0, 0

Where musicfile.mid its your MIDI file..
 and to play it use:

  mciSendString "play tune from 0", vbNullString, 0, 0

To stop the music use:
  mciSendString "stop tune", bNullString, 0, 0

And to close the file:

    mciSendString "close tune", vbNullString, 0, 0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Take out the wait in the MCISENDSTRING PLAY statement.

For example, create a new project and add two command buttons to Form1. Then paste the following code into the DECLARATIONS SECTION of Form1 and run it...

When you click command1, the MIDI will play and when you click command2 it will stop...



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

' Modify the value of the constant "Song" with your path
' to "canyon.mid".
Private Const Song As String = "C:\Windows\Media\Canyon.MID"
Private Sub Command1_Click()
    Dim ret As Long
    ret = mciSendString( _
    "open " & Song & " type sequencer alias canyon", 0&, 0, 0)
    ret = mciSendString("play canyon", 0&, 0, 0)
End Sub
Private Sub Command2_Click()
    ret = mciSendString("stop canyon", 0&, 0, 0)
    ret = mciSendString("close canyon", 0&, 0, 0)
End Sub
mhdhallakAuthor Commented:
ok guys the midi API is working fine for me.
but how can I make it loop whenever it's finsihed?

I need the answer as soon as possible.
ret = mciSendString("play canyon repeat", 0&, 0, 0)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.