Share via


Play Multimedia Files Using MCI Commands Sample

File: ...\Samples\Solution\Forms\Mci_play.scx

This sample form uses the Media Control Interface (MCI) to play multimedia files and can play any visual or non-visual media that is installed on your system. However, the GETFILE( ) function prompts for the most common media files of .avi, .wav, .mov, and .mid. To choose another file, select All Files and choose the desired file. To locate documentation for the MCI commands, see the MSDN Library.

The following three Windows API functions are declared in the Init event of the form:

  • mciSendString

  • mciGetErrorString

  • SetWindowPos

The DoMCI method of the form executes an MCI command that is passed in as a parameter.

Classes

You can open the form to see all the code necessary to run multimedia files, but the functionality has also been extracted into classes that you can easily incorporate into your own applications.

VideoFrame Class

The VideoFrame class in the Visual FoxPro ...\Samples\Classes\Samples.vcx class library can be used to play a visual multimedia file, such as a Video for Windows file. The class makes it possible for you to position and size the video to be played, and then provides built-in methods to easily play the media file.

For an example of using this class, see Video.scx in the Visual FoxPro ...\Samples\Solution\Forms directory.

Property

Description

AutoOpen

Specifies whether the video file should automatically open and display when the object is instantiated. The default value is true (.T.).

AutoPlay

Specifies whether the video file should automatically play when it is opened. The default value is true (.T.).

AutoRepeat

Specifies whether the video file will loop the video. Setting this to .T. will cause the video to play continuously. The default value is false (.F.).

ControlSource

Specifies a Field that contains the video file reference. If empty, the class expects a static file name to be in the VideoFile property.

MCIalias

Specifies the alias to be used by MCI. If left empty, the alias defaults to the Name property of the class. Normally this can be left empty, but if the user wants to play the same video file twice at the same time, a different alias would need to be specified for each.

VideoFile

Holds the name of a video file to play, for example: "D:\...\Samples\Solution\FORMS\FOX.AVI"

Method

Description

CloseVideo

Closes the video file and releases all resources associated with it.

DoMCI

Called by the other methods to execute MCI commands. It also can be called by a user to execute a specific MCI command.

OpenVideo

Opens the video file and shows the first frame.

PauseVideo

Pauses a playing video. The video can be restarted by using the PlayVideo method.

PlayVideo

Plays the video file. The video file must be opened in the OpenVideo method before it can be played.

SetPosition

Makes it possible for the user to specify the position of the media file. It can be executed at any time after the video file has been opened. Valid values are "Start", "End", or a specific millisecond into the video.

Sound Player Class

This class is also contained in the ...\Samples\Classes\Samples.vcx class library. It can be used to play a non-visual multimedia file, such as a waveaudio file. The class makes it possible for you to specify the file to be played, and then provides built-in methods to easily play the media file.

Property

Description

AutoOpen

Specifies whether the sound file should be automatically opened and displayed when the object is instantiated. The default value is true (.T.).

AutoPlay

Specifies whether the sound file should be automatically played when it is opened. The default value is true (.T.).

AutoRepeat

Specifies whether the sound file plays continuously. The default value is false (.F.).

ControlSource

Specifies the column that contains the sound file reference. If empty, the class expects a static file name to be in the SoundFile property.

MCIAlias

Specifies the alias to be used by MCI. If left empty, the alias defaults to the Name property of the class. Normally this can be left empty, but if the user wants to play the same sound file twice at the same time, a different alias would need to be specified for each.

SoundFile

Holds the name of a sound file to play, for example: "C:\WINDOWS\CHIMES.WAV"

Method

Description

OpenSound

Opens the sound file.

PlaySound

Plays the sound file. The file must be opened with the OpenSound method before it can be played.

PauseSound

Pauses the playing of a sound file. Play can be contiued by calling the PlaySound method.

SetPosition

Makes it possible for the user to specify the position of the media file. It can be executed at any time after the file has been opened. Valid values are "Start", "End", or a specific millisecond into the sound.

CloseSound

Closes the sound file and releases all resources associated with it.

See Also

Tasks

Solution Samples

Reference

Visual FoxPro Foundation Classes A-Z

Other Resources

Windows API Solution Samples