void CPlayerDlg::Play()
{
m_nSpeed = 0;
OnThrow0(); // 重設 B 幀丟棄
if(m_bConvert)
Hik_PlayM4_SetDecCallBack(PORT, DecCBFun);
else
m_pMainMenu->EnableMenuItem(ID_FILE_CLOSE, FALSE);
if(m_bPlaying)
{
// 已在播放中:直接重新 Play (切換速度用)
Hik_PlayM4_Play(PORT, GetDlgItem(IDC_SHOW)->m_hWnd);
}
else
{
// 首次播放或停止後重播
if(m_bStreamType)
{
::SetFilePointer(m_hStreamFile, m_nHeadSize, 0, FILE_BEGIN);
Hik_PlayM4_ResetSourceBuffer(PORT);
SetEvent(m_hEventInput);
}
m_bPlaying = Hik_PlayM4_Play(PORT, GetDlgItem(IDC_SHOW)->m_hWnd);
m_bSound = Hik_PlayM4_PlaySound(PORT);
if(m_bPlaying)
SetTimer(PLAY_TIMER, 500, NULL); // 統計計時器
}
if(m_bPlaying)
SetPlayState();
else
{
CString csError;
csError.Format("Play the file faild.(%d)", Hik_PlayM4_GetLastError(PORT));
AfxMessageBox(csError);
}
}
void CPlayerDlg::Pause(BOOL bPause)
{
if(m_bPaused == bPause) return;
m_bPaused = bPause;
Hik_PlayM4_Pause(PORT, bPause);
TRACE("PAUSE %d\n", m_bPaused);
}
void CPlayerDlg::Stop()
{
if(!m_bPlaying) return;
KillTimer(PLAY_TIMER);
if(Hik_PlayM4_StopSound())
{
m_bSound = FALSE;
// 更新音量圖示...
}
m_bPause = FALSE;
m_bPlaying = !Hik_PlayM4_Stop(PORT);
if(!m_bPlaying)
{
SetStopState();
if(m_bStreamType)
ResetEvent(m_hEventInput);
}
}
OpenFile → Play → PlaySoundPause(false) → PlayPlay() 重新呼叫GetLastError 顯示錯誤碼| VC++ 變數 | 型別 | C# 對應 | 用途 |
|---|---|---|---|
m_bPlaying | BOOL | isPlaying | 是否正在播放 |
m_bPaused | BOOL | isPause | 是否暫停 |
m_bSound | BOOL | isSoundOn | 音訊是否播放中 |
m_nSpeed | int | m_nSpeed | 速度層級 (0=正常, ±1~4) |
m_bStreamType | BOOL | isStreamMode | 串流模式 vs 檔案模式 |
下篇將實作 C# 版本的播放/暫停/停止完整代碼。