[MCI 이 페이지와 연결된 기능은 레거시 기능입니다. MediaPlayer 에 의해이 대체되었습니다. MediaPlayer Windows 10 및 Windows 11에 최적화되었습니다. 가능한 경우 새 코드에서 MCI 대신 MediaPlayer 사용하는 것이 좋습니다. 가능한 경우 레거시 API를 사용하는 기존 코드를 다시 작성하여 새 API를 사용하도록 제안합니다.]
다음 예제에서는 CD 오디오 디바이스를 열고, bTrack 매개 변수로 지정된 트랙을 재생하고, 재생이 완료된 후 디바이스를 닫습니다. mciSendCommand 함수를 사용합니다.
// Plays a specified audio track using MCI_OPEN, MCI_PLAY. Returns as
// soon as playback begins. The window procedure function for the
// specified window will be notified when playback is complete.
// Returns 0L on success; otherwise, returns an MCI error code.
DWORD playCDTrack(HWND hWndNotify, BYTE bTrack)
{
UINT wDeviceID;
DWORD dwReturn;
MCI_OPEN_PARMS mciOpenParms;
MCI_SET_PARMS mciSetParms;
MCI_PLAY_PARMS mciPlayParms;
// Open the CD audio device by specifying the device name.
mciOpenParms.lpstrDeviceType = "cdaudio";
if (dwReturn = mciSendCommand(NULL, MCI_OPEN,
MCI_OPEN_TYPE, (DWORD)(LPVOID) &mciOpenParms))
{
// Failed to open device. Don't close it; just return error.
return (dwReturn);
}
// The device opened successfully; get the device ID.
wDeviceID = mciOpenParms.wDeviceID;
// Set the time format to track/minute/second/frame (TMSF).
mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
if (dwReturn = mciSendCommand(wDeviceID, MCI_SET,
MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms))
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}
// Begin play from the specified track and play to the beginning
// of the next track. The window procedure function for the parent
// window will be notified with an MM_MCINOTIFY message when
// playback is complete. Unless the play command fails, the window
// procedure closes the device.
mciPlayParms.dwFrom = 0L;
mciPlayParms.dwTo = 0L;
mciPlayParms.dwFrom = MCI_MAKE_TMSF(bTrack, 0, 0, 0);
mciPlayParms.dwTo = MCI_MAKE_TMSF(bTrack + 1, 0, 0, 0);
mciPlayParms.dwCallback = (DWORD) hWndNotify;
if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY,
MCI_FROM | MCI_TO | MCI_NOTIFY,
(DWORD)(LPVOID) &mciPlayParms))
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}
return (0L);
}
컴팩트 디스크의 트랙을 기준으로 위치를 지정하려면 TMSF(track/minute/second/frame) 시간 형식을 사용해야 합니다.