MCI_PLAY
Appearance
The `MCI_PLAY` message initiates playback for a media device. It allows for specifying start and end positions, as well as device-specific playback modes like fast-forward, reverse, or scan.
Syntax
param1 ULONG ulParam1; /* Playback flags. */ param2 PMCI_PLAY_PARMS pParam2; /* Pointer to a play parameter structure. */
Parameters
- ulParam1 (ULONG) - input
- The following general flags apply to all devices:
- MCI_NOTIFY Posts a notification message when the action completes.
- MCI_WAIT Does not return control until playback reaches the "To" position or is stopped.
- MCI_FROM Uses the ulFrom field in pParam2 as the start position. Defaults to current position if not set.
- MCI_TO Uses the ulTo field in pParam2 as the end position. Defaults to the end of media if not set.
- Digital Video Extensions
- Additional flags for digital video:
- MCI_DGV_PLAY_SPEED Uses the ulSpeed field for playback rate.
- MCI_DGV_PLAY_REVERSE Plays the video in reverse.
- MCI_DGV_PLAY_FAST Plays at twice the normal rate.
- MCI_DGV_PLAY_SLOW Plays at half the normal rate.
- MCI_DGV_PLAY_SCAN Plays as quickly as possible with audio disabled.
- Videodisc Extensions
- Additional flags for videodiscs (Reverse and Scan are mutually exclusive):
- MCI_VD_PLAY_REVERSE, MCI_VD_PLAY_FAST, MCI_VD_PLAY_SCAN, MCI_VD_PLAY_SPEED, MCI_VD_PLAY_SLOW.
- pParam2 (PMCI_PLAY_PARMS) - input
- Points to an MCI_PLAY_PARMS structure. For extended devices, this may point to MCI_DGV_PLAY_PARMS or MCI_VD_PLAY_PARMS.
Returns
- rc (ULONG) - returns
- * MCIERR_SUCCESS Playback started successfully.
- MCIERR_DEVICE_NOT_READY The device is busy or has no media.
- MCIERR_OUTOFRANGE The "From" or "To" positions are invalid.
- MCIERR_CHANNEL_OFF The primary audio/video channel is disabled.
Remarks
Positions provided in `ulFrom` and `ulTo` must match the currently set time format (e.g., milliseconds, frames, or MMTIME).
When playback reaches the `ulTo` position:
- The current position of the media is updated to the `ulTo` value.
- If a file has 100 samples (0–99) and you play from 10 to 80, samples 10 through 79 are played. The final position will be 80.
> [!IMPORTANT] > **Digital Video Deadlock:** If your application uses the `MCI_WAIT` flag on the main GUI thread without direct-access drivers, the application may hang. Always use a separate thread for `MCI_WAIT` operations or use `MCI_NOTIFY`.
Example Code
The following code initiates playback from the 5-second mark to the 25-second mark, assuming the time format is set to milliseconds.
USHORT usDeviceID;
MCI_PLAY_PARMS mpp;
/* Setup callback for notification when 25s is reached */
mpp.hwndCallback = (HWND) hwndMyWindow;
/* Set positions in milliseconds */
mpp.ulFrom = (ULONG) 5000;
mpp.ulTo = (ULONG) 25000;
mciSendCommand(usDeviceID,
MCI_PLAY,
MCI_NOTIFY | MCI_FROM | MCI_TO,
(PVOID) &mpp,
0);
Related Messages
- MCI_SET (to change time format)
- MCI_STOP
- MCI_PAUSE
- MCI_RESUME