The Computer Guy

Using the Media Control Interface

Clarion for Windows Tips
October 1996
Sample program icon Download the sample code


The Windows API provides two methods for controlling the multimedia capabilities of the system. The first is a series of low-level functions. The second is the Windows Media Control Interface (MCI). The media control interface provides a high-level, device-independent interface for controlling multimedia devices on the system and is the recommended method for controlling multimedia devices in Windows.

There are two methods for issuing MCI commands: command messages and command strings. Command messages are sent by filling a memory structure (GROUP) and passing it to the MCI system. Command strings are English-like strings that are sent to the MCI system and parsed to determine the action to be taken. Command strings provide the same functionality as command messages with a simpler format. This tip examines how to use the media control interface using MCI command strings.


Using MCI, a program has the ability to play and record (as appropriate) on any supported multimedia device. This includes the usual multimedia devices (wave audio, MIDI sequencer, CD audio) as well as some more unusual devices (VCR, videodisc, digital audio tape). The configuration information for MCI is stored in the WIN.INI and SYSTEM.INI files. The [mci] section of SYSTEM.INI maps the system device names to the device drivers controlling those devices. The [mci extensions] section of WIN.INI maps file extensions to the appropriate multimedia device.

The MCI configuration information for my system is shown below. There are five multimedia devices registered on the system: CD audio, MIDI sequencer, wave audio, AVI video and MPEG video.

[mci]
cdaudio=mcicda.drv
sequencer=mciseq.drv
waveaudio=mciwave.drv
avivideo=mciavi.drv
MPEGVideo=mciqtz.drv

This configuration method makes MCI extensible. New multimedia devices with the proper drivers can be integrated with the MCI system even though the devices weren't invented when MCI was designed. The system can also use multiple devices of the same type by configuring them correctly in SYSTEM.INI. I recently completed a project using a “CD jukebox” - a five-platter CD-ROM unit. After modifying the MCI configuration information, I was able to address each of the CD-ROM platters as an independent device.

The MCI system commands are divided into four categories: system, required, basic and extended commands. The commands are described below along with some commonly used options.

MCI System Commands

System commands are handled by the MCI system instead of by an MCI device. These commands provides provide system-level information. The system commands are break and sysinfo.

Command Description
break Set up key to break MCI action
sysinfo Gets MCI system information
sysinfo all quantity
sysinfo all name [index]
sysinfo cdaudio quantity

Required Commands

Required commands must be implemented for every device. Each device must also support a defined set of options for each command. The required commands are capability, close, info, open and status.

Command Description
capability Gets information about device capabilities
capability cdaudio can eject
close Closes an open device
close all
close cdaudio
info Gets information about the device driver
info cdaudio product
open Opens and initializes a device
open cdaudio
open waveaudio!c:\win95\media\chimes.wav
open c:\win95\media\chimes.wav type waveaudio
open waveaudio!chimes.wav alias chimesound
open sequencer!canada.mid
open canada.mid type sequencer alias anthem
status Gets device status
status cdaudio mode
status sequencer mode

Basic Commands

Basic commands are device control commands that are may or may not be implemented depending on the device. The commands that are implemented must support a standard set of options for that command. The basic commands are load, pause, play, record, resume, save, seek, set, status and stop.

Command Description
load Loads a device file from disk
pause Pauses playing or recording
pause cdaudio
pause anthem
play Starts playing the device
play cdaudio
play cdaudio from 3 to 4
play waveaudio
play chimesound
record Starts recording data with the device
record waveaudio
resume Resumes playing or recording after pause
resume cdaudio
save Save a device file to disk
save waveaudio c:\temp\newsound.wav
seek Moves to a specified position for the device
seek cdaudio to start
seek cdaudio to 3
seek waveaudio to 1000
set Updates device control settings
set cdaudio door open
set cdaudio door closed
set waveaudio time format milliseconds
set cdaudio time format tmsf
status Gets device status
status cdaudio current track
status anthem length
status cdaudio length track 3
status cdaudio number of tracks
status waveaudio time format
stop Stops playing or recording
stop cdaudio
stop anthem

Extended Commands

Extended commands are additional commands that may be implemented for a specific device or that extended that options on a required or basic command. Examples of extended commands are delete and spin. Delete is used to delete a section of a wave audio file. Spin is used to start or stop spinning on a videodisc device. These commands are implemented only for the devices they apply to.

The MCI Command String Functions

Two API functions are involved when using MCI command strings: mciSendString and mciGetErrorString. The functions are prototyped and used in the Media Control Interface Tester sample program. This program allows the user to enter and execute an MCI command string. The program provides a way to test the result of various MCI command strings.

The program includes some sample MIDI files for testing. You can use these along with other multimedia files on your system to test some of the following command strings and see their results.

To test the wave audio device on your system, try:

open c:\win95\media\chimes.wav type waveaudio
play c:\win95\media\chimes.wav
close c:\win95\media\chimes.wav
open c:\win95\media\chimes.wav type waveaudio alias chimes
play chimes
close chimes
open waveaudio!c:\win95\media\chimes.wav alias chimes
play chimes
close chimes

To test the MIDI sequencer on your system, try:

open sequencer!canada.mid alias anthem
play anthem
pause anthem
resume anthem
stop anthem
seek anthem to start
play anthem
stop anthem
close anthem

To test the CD drive on your system, try:

open cdaudio
play cdaudio
set cdaudio time format tmsf
play cdaudio from 3 to 4
close cdaudio

If you do much work with the MCI system, you will probably want to obtain a Windows API reference so that you have full documentation for the MCI command structure. For basic MCI work, you now have to tools needed to integrate the media control interface and its capabilities into your Clarion programs.


HomeContact information
Copyright 1995–2008 — The Computer Guy
Last updated Sunday, October 5, 2008