Click here for a
complete OFFICIAL
list of ALL MCI
Commands
                    

Home
AVI (Audio Visual)
WAV (Sound/Audio)
MIDI(Sequence/Music)
CD (CD Audio)
Download
Links
FAQ
Email
MIDI Music
    A MIDI file is a music file that can be played in Windows.

If you have Visual Basic 4.0 or newer then copy and paste this code into a module. (eg. module1.bas)
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


If you have Visual Basic 3.0 then copy and paste this code into a module. (eg. module1.bas)

Declare Function mciSendString Lib "mmsystem" (ByVal lpstrCommand$, ByVal lpstrReturnStr As Any, ByVal wReturnLen%, ByVal hCallBack%) As Long


OPEN
     We must OPEN a MIDI file before we can do anything to with it. All of the other MCI commands listed on this web page require that the OPEN command to be used first, otherwise they will not work. The type of multimedia file we want to use is sequencer and the alias name that we will use to refer to the MIDI file is mid1 (Although we can use any alias name you desire, such as "Mymidi", "mid2", "john1", etc... , we'll use mid1 for easy reference in the examples that follow).
  i = mciSendString("open c:\music.mid type sequencer alias mid1", 0&, 0, 0)
PLAY
     When a MIDI file is open, we can play it. The keyword in this command is PLAY. Notice that we use the alias mid1. This is the same as typing in c:\myvmidi.mid, but use the alias because you can always refer to the same midi file throughout your entire VB program without using a global variable.
  i = mciSendString("play mid1", 0&, 0, 0)
Play from...
     You don't have to start playing a MID file from the beginning. You can start anywhere within the file. This example starts at the 3000 (3000 milliseconds) position and plays to the end.
  i = mciSendString("play mid1 from 3000", 0&, 0, 0)
Play from to...
     Perhaps you have a MID file that contains different tunes. You may want to hear certain tunes. You will need code to play a specific portion or parameter of the MID file.
  i = mciSendString("play mid1 from 1000 to 2000", 0&, 0, 0)
TEMPO
     The tempo (or speed) of a MID file can be changed. The sample sets the speed to 300.
  i = mciSendString("set mid1 tempo 300", 0&, 0, 0)
Wait...
     A MIDI file can be played without any interruption from other Windows. The wait command sets the focus entirely on playing the MIDI file until it has reached the end. It is a good idea not to use this command on long, time-consuming files. You are virtually "locked out" of your computer until the file completely finishes playing.
  i = mciSendString("play mid1 wait", 0&, 0, 0)
Pause
     While a MIDI file is being played, you can pause it. Use the resume command to resume playing or recording.
     Note: The pause command is good to use, especially when using a timer control to loop a MIDI file repeatedly. Your timer control should detect a stopped flag and obey it by playing from zero, but when a pause flag is detected, you can over rule the timer settings and pause the MIDI.
  i =  mciSendString("pause mid1", 0&, 0, 0)
SEEK
     You can use this command to reposition the current location within your MIDI file.


Seek to position 2000
 i = mciSendString("seek mid1 to 2000", 0&, 0, 0)
Seek to beginning of WAV
 
 i = mciSendString("seek mid1 to start", 0&, 0, 0)
Seek to end of WAV
 i = mciSendString("seek mid1 to end", 0&, 0, 0)
Resume...
     When a MIDI file is paused, you can resume and continue playing it.
  i =  mciSendString("resume mid1", 0&, 0, 0)
Stop...
     While a MIDI file is being played, you can stop it. Use the play command to start playing the file again.
  i =  mciSendString("stop mid1", 0&, 0, 0)
TIP: You can use the code below to play a MIDI file that has been stopped. This gives the user the "rewind illusion" that once a MIDI file is stopped (much like a music CD), it will start from the beginning when played again.
  i = mciSendString("play mid1 from 0", 0&, 0, 0)
Close...
     Probably the most important command is the close command. You should always MAKE SURE that your MIDI file is closed after you have finished using it, especially when you end your program. It is a good idea to add this close command in the "Form_Unload" sub. Not closing a MIDI file will cause problems within WINDOWS, because the opened MIDI file will remain open, known as "being used", or "hanging".
 i = mciSendString("close mid1", 0&, 0, 0)
Hosted by www.Geocities.ws

1