?
Solved

Plaing MIDI using API

Posted on 1999-11-24
6
Medium Priority
?
213 Views
Last Modified: 2010-05-02
Without using the MCI Control, how do i play a midi file using API declaration?
0
Comment
Question by:mhdhallak
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 40 total points
ID: 2233517
This microsot KB article will do what you want...

HOWTO: Play MIDI Files Using API Functions
http://support.microsoft.com/support/kb/articles/Q171/9/80.asp 
 

Cheers!
0
 

Author Comment

by:mhdhallak
ID: 2234742
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?
0
 

Expert Comment

by:marginal
ID: 2234775
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
mciSendString

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
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 14

Expert Comment

by:mcrider
ID: 2234781
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...

Cheers!


THE 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

' 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
0
 

Author Comment

by:mhdhallak
ID: 2242502
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.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2244266
ret = mciSendString("play canyon repeat", 0&, 0, 0)

Cheers!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question