Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitlePlay a MIDI file by using the MCI control
DescriptionThis example shows how to play a MIDI file by using the MCI control in Visual Basic 6.
KeywordsMIDI, audio, MCI, multimedia
CategoriesMultimedia
 
When the program starts, it initializes the MCI control.

When the user clicks the Play button, the program sets the control's FileName property to the name of the MIDI file, sets Wait to True so the control opens the file synchronously, and sets Command = Open to open the file. It then sets Command = Play to play the file. It does not set Wait = True first so the play is asynchronous.

When the control finishes playing, the program closes the file and re-enables the Play button.

 
Private Sub Form_Load()
    txtFilename.Text = App.Path
    If Right$(txtFilename.Text, 1) <> "\" _
        Then txtFilename.Text = txtFilename.Text & "\"
    txtFilename.Text = txtFilename.Text & "Passport.mid"

    ' Prepare the MCI control for WaveAudio.
    MMControl1.Notify = False
    MMControl1.Wait = True
    MMControl1.Shareable = False
    MMControl1.DeviceType = "Sequencer"
End Sub

' Open the device and play the sound.
Private Sub cmdPlay_Click()
    cmdPlay.Enabled = False

    ' Set the file name.
    MMControl1.FileName = txtFilename.Text

    ' Open the MCI device.
    MMControl1.Wait = True
    MMControl1.Command = "Open"

    ' Play the sound without waiting.
    MMControl1.Command = "Play"
End Sub

' Close the device.
Private Sub MMControl1_Done(NotifyCode As Integer)
    MMControl1.Command = "Close"
    cmdPlay.Enabled = True
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated