14#pragma comment(lib, "winmm.lib")
43 CMciPlayer(
void) : m_isPlayed(false), m_lastError(0), m_hParent(NULL), m_wDeviceId(0), m_hViewWnd(NULL), m_isPaused(false)
81 LPCTSTR lpszDeviceType =
reinterpret_cast<LPCTSTR
>(MCI_DEVTYPE_SEQUENCER);
82 return Open(lpszFileName, lpszDeviceType,
true);
93 LPCTSTR lpszDeviceType = _T(
"MPEGVideo");
94 return Open(lpszFileName, lpszDeviceType,
false);
105 LPCTSTR lpszDeviceType =
reinterpret_cast<LPCTSTR
>(MCI_DEVTYPE_WAVEFORM_AUDIO);
106 return Open(lpszFileName, lpszDeviceType,
true);
117 bool OpenAvi(LPCTSTR lpszFileName, HWND hViewWnd)
119 LPCTSTR lpszDeviceType = _T(
"MPEGVideo");
120 return Open(lpszFileName, lpszDeviceType,
false, hViewWnd);
131 if ( m_wDeviceId != 0 )
133 r = m_Cmd(MCI_CLOSE);
164 return m_GetStatus(_ms, MCI_STATUS_LENGTH);
178 if ( m_GetStatus(mode, MCI_STATUS_MODE) )
182 return MCI_MODE_NOT_READY;
193 MCI_PLAY_PARMS mciPlay = { 0 };
194 bool r = m_Cmd(MCI_PLAY, 0, mciPlay);
210 bool r = m_Cmd(MCI_STOP);
230 r = m_Cmd(isPause ? MCI_PAUSE : MCI_PLAY);
233 m_isPaused = isPause;
246 if ( m_isPlayed &&
GetMode() == MCI_MODE_PAUSE )
260 bool Seek(DWORD pos = 0,
bool isResume =
true)
264 return m_Cmd(MCI_SEEK, MCI_SEEK_TO_START);
266 MCI_SEEK_PARMS mciSeek = { 0 };
268 bool r = m_Cmd(MCI_SEEK, MCI_TO, mciSeek);
284 MCI_DGV_SETAUDIO_PARMS parm = { 0 };
285 parm.dwItem = MCI_DGV_SETAUDIO_VOLUME;
287 return m_Cmd(MCI_SETAUDIO, MCI_DGV_SETAUDIO_ITEM | MCI_DGV_SETAUDIO_VALUE, parm);
299 return m_GetStatus(_ms, MCI_STATUS_POSITION);
311 MCI_DGV_PUT_PARMS parms = { 0 };
313 return m_Cmd(MCI_PUT, MCI_DGV_RECT | MCI_DGV_PUT_DESTINATION, parms);
325 MCI_ANIM_RECT_PARMS parms = { 0 };
326 if ( m_Cmd(MCI_WHERE, MCI_ANIM_WHERE_SOURCE, parms) )
328 _size.cx = parms.rc.right - parms.rc.left;
329 _size.cy = parms.rc.bottom - parms.rc.top;
352 if ( e != MMSYSERR_NOERROR )
354 ::mciGetErrorString(e, s.
GetBuffer(1000), 1000);
371 bool Open(LPCTSTR lpszFileName, LPCTSTR lpszDeviceType,
bool isDeviceTypeId, HWND hViewWnd = NULL)
378 DWORD p1 = MCI_OPEN_TYPE | MCI_OPEN_ELEMENT | (isDeviceTypeId ? MCI_OPEN_TYPE_ID : 0);
380 if ( hViewWnd == NULL )
383 m_openParms.lpstrDeviceType = lpszDeviceType;
384 m_openParms.lpstrElementName = lpszFileName;
385 p2 =
reinterpret_cast<DWORD
>(&m_openParms);
389 Zero(m_animOpenParms);
390 m_animOpenParms.hWndParent = hViewWnd;
391 m_animOpenParms.dwStyle = WS_CHILD;
392 m_animOpenParms.lpstrDeviceType = lpszDeviceType;
393 m_animOpenParms.lpstrElementName = lpszFileName;
394 p1 |= (MCI_ANIM_OPEN_PARENT | MCI_ANIM_OPEN_WS);
395 p2 =
reinterpret_cast<DWORD
>(&m_animOpenParms);
397 bool r = m_Rst(::mciSendCommand(NULL, MCI_OPEN, p1, p2));
400 m_hViewWnd = hViewWnd;
401 if ( hViewWnd == NULL )
403 m_wDeviceId = m_openParms.wDeviceID;
407 m_wDeviceId = m_animOpenParms.wDeviceID;
412 MCI_SET_PARMS mciSet = { 0 };
413 mciSet.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
414 r = m_Cmd(MCI_SET, MCI_SET_TIME_FORMAT, mciSet);
416 if ( r && m_hViewWnd != NULL )
419 ::GetClientRect(m_hViewWnd, &rc);
420 MCI_DGV_PUT_PARMS parms = { 0 };
422 r = m_Cmd(MCI_PUT, MCI_DGV_RECT | MCI_DGV_PUT_DESTINATION, parms);
438 bool m_RstFx(MCIERROR r)
const
444 bool m_Rst(MCIERROR r)
const
454 template<
typename TYP>
455 bool m_Cmd(UINT msg, DWORD param, TYP& typ)
const
459 if ( m_hParent != NULL )
461 typ.dwCallback =
reinterpret_cast<DWORD
>(m_hParent);
464 return m_Rst(::mciSendCommand(
GetDeviceId(), msg, param,
reinterpret_cast<DWORD
>(&typ)));
466 return m_RstFx(MCIERR_DEVICE_NOT_READY);
469 bool m_Cmd(UINT msg, DWORD param = 0)
const
471 MCI_GENERIC_PARMS p = { 0 };
472 return m_Cmd(msg, param, p);
475 bool m_GetStatus(DWORD& _status, DWORD item)
const
477 MCI_STATUS_PARMS mciStatus = { 0 };
478 mciStatus.dwItem = item;
479 bool r = m_Cmd(MCI_STATUS, MCI_STATUS_ITEM, mciStatus);
482 _status = mciStatus.dwReturn;
486 MCI_OPEN_PARMS m_openParms;
487 MCI_ANIM_OPEN_PARMS m_animOpenParms;
488 MCIDEVICEID m_wDeviceId;
493 mutable MCIERROR m_lastError;
MCIERROR GetLastError(void) const
[取得] ラストエラーコード取得.
bool Close(void)
[設定] クローズ.
bool GetSourceSize(SIZE &_size) const
[取得] 画像大きさ取得.
void SetParentWnd(HWND hWnd)
[設定] 親ウィンドウ設定.
bool GetPlayingPosition(DWORD &_ms) const
[取得] 演奏位置取得.
bool OpenAvi(LPCTSTR lpszFileName, HWND hViewWnd)
[設定] AVI ファイルオープン.
DWORD GetMode(void) const
[取得] モード取得.
static CStr GetErrorString(MCIERROR e)
[取得] エラー文字列取得.
bool Seek(DWORD pos=0, bool isResume=true)
[設定] シーク.
bool Pause(bool isPause=true)
[設定] 演奏中断・再開.
bool OpenWave(LPCTSTR lpszFileName)
[設定] WAVE ファイルオープン.
bool IsPaused(void) const
[取得] 一時停止中?
bool OpenMidi(LPCTSTR lpszFileName)
[設定] MIDI ファイルオープン.
bool IsOpened(void) const
[取得] オープン確認.
bool GetLength(DWORD &_ms) const
[取得] 全演奏時間.
bool Open(LPCTSTR lpszFileName, LPCTSTR lpszDeviceType, bool isDeviceTypeId, HWND hViewWnd=NULL)
[設定] オープン.
bool SetVolume(DWORD vol)
[設定] 音量設定.
void SetLastError(MCIERROR e)
[設定] ラストエラーコード設定.
bool Play(void)
[設定] 演奏開始.
MCIDEVICEID GetDeviceId() const
[取得] デバイス ID 取得.
bool SetViewRect(const RECT &rect)
[設定] 表示RECT設定.
bool Stop(void)
[設定] 演奏停止.
bool OpenMp3(LPCTSTR lpszFileName)
[設定] MP3 ファイルオープン.
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
void Zero(V &value)
[設定] ゼロクリア.