Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Nov 13, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Play an AVI movie

If you want to play an AVI movie from VB you can use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:

Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
    lpstrCommand As String, ByVal lpstrReturnString As String, _
    ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
The first argument is the command string, lpstrReturnString receives return information (if needed), uReturnLength indicates the size, in characters, of lpstrReturnString, and hwndCallback is used for system notification. Remember that every command string described in this tip must be sent to the system with:

CommandString = "Your MCI command here"
RetVal = mciSendString(CommandString, vbNullString, 0, 0)
First you must open the AVI device with

CommandString = "Open " + FileName + " type avivideo alias AVIFile"
Notice that FileName must be in the short format 8.3 characters; lpstrReturnString is null because you don't need any return information. "AVIFile" is an arbitrary name that you'll use in subsequent command strings as an alias of the filename. Once you've opened the file you you can start playing it with the following command:

CommandString = "Play AVIFile wait"
You can also play it full screen with:

CommandString = "Play AVIFile fullscreen wait"
The execution is synchronous, but you can play the file asynchronously and receive notifications with one of these commands:

' play an AVI movie with callback notifications
CommandString = "Play AVIFile notify"
RetVal = mciSendString(CommandString, vbNullString, 0, MyForm.hWnd)

' play an AVI movie full screen with callback notifications
CommandString = "Play AVIFile fullscreen notify"
RetVal = mciSendString(CommandString, vbNullString, 0, MyForm.hWnd)
where MyForm is the form you are using. The system sends your form a MM_MCINOTIFY message when the playback is finished. To intercept this message you have to create a custom window procedure and use a subclassing technique.

By default playback begins at the current position and stops at the end of the content, but you can play only a part of the file with:

CommandString = "Play AVIFile from X to Y"
X and Y are two different positions. It's often useful to specify X and Y in milliseconds, so before Play command you might use this command:

CommandString = "Set AVIFile time format milliseconds"
With asynchronous executions, you can pause / resume and stop playback with

' pause an AVI file
CommandString = "Pause AVIFile"
' resume a paused AVI file
CommandString = "Resume AVIFile"
' stop an AVI file
CommandString = "Stop AVIFile"
To play a movie without the audio send this string before the play command:

CommandString = "set AVIFile audio all off"
and you can also play just the audio track:

CommandString = "Set AVIFile video off"
When you have finished to work with the AVI device, you must close it with

CommandString = "Close AVIFile"
Alberto Falossi
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date