The Multimedia control allows you to manage Media Control Interface (MCI) devices. These devices include: sound boards, MIDI sequencers, CD-ROM drives, audio players, videodisc players, and videotape recorders and players.
This Multimedia control contains a set of push buttons that issue MCI commands which resemble the commands (functions) you would expect to see on a typical compact disc player or videotape recorder.
The Multimedia control
The buttons are defined, from left to right, as Prev, Next, Play, Pause, Back, Step, Stop, Record, and Eject.
Which buttons you use, and the functions provided to you by the Multimedia control, depend on the hardware and software configurations of a particular machine. For instance, if your application uses specific multimedia devices and drivers, they must be installed on the user's machine.
Driver support for many multimedia devices (audio and video files, for instance) is provided for in the Windows 95 and Windows NT operating systems. Other devices, such as digital audio tape players or image scanners require separate drivers, are usually provided by the manufacturer.
Devices are considered to be of two types: simple and compound. Simple multimedia devices do not require a data file for playback. For example, when Videodisc and CD audio players are opened, you play, rewind, or forward through 'tracks'. Compound devices, however, require a data file for playback.
The following table lists some of the devices supported by the Multimedia control and the string required by the DeviceType property to use the device. Those listing an accompanying file type are compound devices.
Device type | String | File Type | Description |
CD audio | CDAudio | CD audio player | |
Digital Audio Tape | DAT | Digital audio tape player | |
Digital video | DigitalVideo | Digital video in a window (not GDI-based) | |
Other | Other | Undefined MCI device | |
Overlay | Overlay | Overlay device | |
Scanner | Scanner | Image scanner | |
Sequencer | Sequencer | .mid | Musical Instrument Digital Interface (MIDI) sequencer |
Vcr | VCR | Video cassette recorder or player | |
AVI | AVIVideo | .avi | Audio Visual Interleaved video. |
Videodisc | Videodisc | Videodisc player | |
Wave audio | Waveaudio | .wav | Wave device that plays digitized waveform files. |
The Multimedia control uses a set of high-level, device-independent commands, known as Media Control Interface commands, that control various multimedia devices. Many of these commands correspond directly to a button on the Multimedia control. For instance, the Play command corresponds to the Play button.
The Multimedia control is essentially a Visual Basic interface to this command set. Commands like Play or Close have equivalents in the MCI command structure of the Win32® API. For instance, Play corresponds to MCI_PLAY. The following table lists the MCI commands used by the Multimedia control, along with their Win32 equivalents:
Command | MCI Command | Description |
Open | MCI_OPEN | Opens a MCI device. |
Close | MCI_CLOSE | Closes a MCI device. |
Play | MCI_PLAY | Plays a MCI device. |
Pause | MCI_PAUSE or MCI_RESUME | Pauses playing or recording. |
Stop | MCI_STOP | Stops a MCI device. |
Back | MCI_STEP | Steps backward through available tracks. |
Step | MCI_STEP | Steps forward through available tracks. |
Prev | MCI_SEEK | Goes to the beginning of the current track using the Seek command. If executed within three seconds of the previous Prev command, goes to the beginning of the previous track or to the beginning of the first track if at the first track. |
Next | MCI_SEEK | Goes to the beginning of the next track (if at last track, goes to the beginning of the last track) using the Seek command. |
Seek | MCI_SEEK | Seeks track forward or backward. |
Record | MCI_RECORD | Records MCI device input. |
Eject | MCI_SET | Ejects Audio CD from CD drive. |
Save | MCI_SAVE | Saves an open file. |
In Visual Basic, these commands are initiated using the Multimedia control's Command property. For example:
MMControl1.Command = "Open"
While the Multimedia control's implementation of the MCI command set is sufficient for most uses, directly utilizing the Win32 API can provide advanced programming functions and techniques.
For More Information For additional information on the MCI commands see the Microsoft Multimedia Development Kit Programmer's Workbook or the Microsoft Windows Software Development Kit Multimedia Programmer's Reference. These references, and a wealth of other information on the MCI commands, are available on the Microsoft Developer Network CD.
The Multimedia Control can be either visible or invisible at run time by setting the Enabled and Visible properties. By default, the Enabled and Visible properties are set to True and the control is visible at run time.
If you do not want the user to interact directly with the buttons on the Multimedia control but want to use the control for its multimedia functionality, set the Visible property to False. An application can control MCI devices with or without user interaction.
To enable or make individual buttons visible or invisible, you set each button's visible and enabled properties. For example, the Back button contains the properties BackEnabled and BackVisible. Each of the nine push buttons have corresponding properties.
In most cases, the default functionality of the individual buttons is sufficient to manage MCI devices. However, the Multimedia control contains run-time properties which allow you to augment or redefine the button commands.
The Notify, NotifyMessage, and NotifyValue properties provide valuable feedback on the failure or completion of a command.
After you place the Multimedia control on a form, whether it is set to be visible or not, the first step is accessing the MCI device. To do this, you set a number of run-time properties. For example:
'Set initial property values of the media device
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "CDAudio"
The Notify property, if set to True, generates a Done event when next command is completed. The Done event provides useful feedback indicating the success or failure of the command. The Wait property determines whether or not the Multimedia control waits for the next command to complete before returning control to the application. The Shareable property either restricts or allows use of the media device by other applications or processes. The DeviceType property is used to specify the type of MCI device.
Finally, the Open command is used to open the MCI device.
'Open the media device
MMControl1.Command = "Open"
When the control is visible, setting these properties and issuing the Open command enables the push buttons of the Multimedia control that are inherently supported by the MCI device. For instance, opening the cdaudio device enables the Prev, Next, Play, and Eject buttons. When Play is pressed, the Stop and Pause buttons are enabled.
Multiple instances of the Multimedia control can be added to a form to provide concurrent control of several MCI devices. You use one control per device.
To properly manage multimedia and system resources, you should close those MCI devices that are open before exiting your application. You can place the following statement in the Form_Unload procedure to close an open MCI device when the form containing the Multimedia control is unloaded.
Private Sub Form_Unload (Cancel as Integer)
Form1.MMControl1.Command = "Close"
End Sub
You can handle errors encountered by the Multimedia control using the Error and ErrorMessage properties. You can test for an error condition after each command. For example, following the Open command, you check the value of the Error property to test for the existence of a CD drive. If the CD drive is not available, an error message is returned. For example:
If Form1.MMControl1.Error Then
MsgBox Form1.MMControl1.ErrorMessage,vbCritical, "CD Player not installed or not working properly"
End If
For More Information See "ErrorMessage Property (Multimedia MCI Control)" and "Error Property (Multimedia MCI Control)".