DISCOVER
×

How to use mmcontrol in visual basic

Updated March 23, 2017

The Microsoft Multimedia Control, or MMControl, is a Visual Basic tool that plays media files. You will not find MMControl to be one of the default tools in your toolbox, but you can add it to your list of controls with the Components list. You can add MMControl so you can integrate audio or video files to your project. However, MMControl accepts only one file at a time, so if you want to create your own MP3 player, you will need to use an array to store your track list.

Open a Visual Basic project. Click on "Project" from the menu, and select "Components." Scroll down to "Microsoft Multimedia Control 6.0," and double-click it to add a check box to the selection. Click "OK" to close the Components window. This adds MMControl to your toolbox.

Double click the MMControl tool in the toolbox to add one to your form. Click and drag the control to a point on the form where you need it.

Open the code window. Type "Dim track List(4) As String" at the top. This will create an array that will hold five tracks (numbered zero to four). Type "Dim track Number As Integer" to create a counter variable.

Open the "Form_Load()" function. Type "track List(0) = file_path" to load your first track into your array, where "file_path" is the actual location of your MP3 file on your computer. Do this again for "track(List(1)" to "track List(4)."

Type "MMControl1.Command = "Open"" in the "Form_Load()" function to open the device when the program starts. Type "track Number = 0" on the next line and "MMControl1.FileName = track List(trackNumber)" on the line after that. Type "MMControl.Command = "Play" on the final line in the function.

Open the "Form_Unload" function, and type "MMControl.Command = "Close"" to stop the control when your program ends.

Open the "MMControl1_NextClick" function. Type the following lines:

MMControl1.Command = "Stop"

If track Number = 4 Then

track Number = 0

Else

track Number = track Number + 1

End If

MMControl1.FileName = list(trackNumber)

MMControl1.Command = "Open"

MMControl1.Command = "Play"

Open the "MMControl1_PrevClick" function. Type the following lines:

MMControl1.Command = "Stop"

If track Number = 0 Then

track Number = 4

Else

track Number = track Number - 1

End If

MMControl1.FileName = list(trackNumber)

MMControl1.Command = "Open"

MMControl1.Command = "Play"

Press "F5" to start your program and listen to your MP3s.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Laura Gittins has been writing since 2008 and is an expert in document design. She has a Bachelor of Science in English, Professional and Technical Writing. She has written education and document design articles for eHow.