TMci
Source: source/classes/tmci.prg
Standalone class
TMci provides multimedia playback control through the Windows Media Control Interface (MCI) API. It supports audio and video file playback including AVI video, CD audio, WAV, MIDI, and other MCI-compatible devices. The class can play media in a window or full-screen.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
nError | Numeric | Last MCI error code; zero indicates success |
nId | Numeric | MCI device identifier assigned on open |
cType | Character | Device type: "AVIVideo", "CDAudio", "WaveAudio", "Sequencer", etc. |
cFileName | Character | Path to the multimedia file being played |
oWnd | Object | Parent window for video playback |
Methods
| Method | Description |
|---|---|
New( cDev, cFile ) | Create a new MCI object for the given device type and media file |
lOpen() | Open the MCI device; returns .T. on success |
Play( nFrom, nTo, hWnd ) | Play a segment from nFrom to nTo, optionally in a window handle |
PlayFull() | Play media in full-screen mode |
SetWindow( oWnd ) | Set the parent window for video output |
Position() | Return the current playback position |
Length() | Return the total media length |
SendStr( cMci ) | Send a raw MCI command string directly to the device |
cGetError() | Return a human-readable description of the last error |
End() | Close the MCI device and release resources |
Example: Play AVI File
#include "FiveWin.ch"
function Main()
local oMci, oWnd
DEFINE WINDOW oWnd TITLE "MCI Video Player" SIZE 640, 480
oMci := TMci():New( "AVIVideo", "sample.avi" )
if oMci:lOpen()
oMci:SetWindow( oWnd )
oMci:Play()
MsgInfo( "Playing: " + oMci:cFileName )
else
MsgStop( "Cannot open: " + oMci:cGetError() )
endif
ACTIVATE WINDOW oWnd CENTERED
oMci:End()
return nil
Notes
- The
cTypeparameter determines which MCI driver is loaded. Common types include "AVIVideo", "WaveAudio", "CDAudio", and "Sequencer" (MIDI). - Call
lOpen()before any playback operation. Check the return value to confirm the device was opened successfully. - Use
Play()with a window handle to embed video in your application UI, orPlayFull()for full-screen playback. - The
SendStr()method provides low-level access to any MCI command string for advanced operations not covered by the class methods. - Always call
End()when finished to release the MCI device and avoid resource leaks.