C#視頻監控系列(13):H264播放器——控制播放和截圖

來源:互聯網
上載者:User

一、控制播放

1.1 暫停/播放/停止

VC++ Code:

////////////////////////////////////////////////////////////////////////////////
//Funtion:Play or change the play speed to normal;
///////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnPlay()
{
    // TODO: Add your control notification handler code here
    Play();
}

void CPlayerDlg::Play()
{
    m_nSpeed=0;
    OnThrow0();
//#ifdef _TEST_CALLBACK
    if(m_bConvert)
       Hik_PlayM4_SetDecCallBack(PORT,DecCBFun);
    else
        m_pMainMenu->EnableMenuItem(ID_FILE_CLOSE, FALSE);
//#endif
    if(m_bPlaying)
    {
        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);
    }

}
//////////////////////////////////////////////////////////////////////////////
//Funtion:pause.
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnPause()
{
    // TODO: Add your control notification handler code here
    if(m_bPlaying)
    {
        m_bPause=!m_bPause;
        Pause(m_bPause);
    }
}
void CPlayerDlg::Pause(BOOL bPause)
{
    if(m_bPaused == bPause)
        return;
    m_bPaused=bPause;
    Hik_PlayM4_Pause(PORT,bPause);
    TRACE("PAUSE %d\n",m_bPaused);
}
/////////////////////////////////////////////////////////////////////////////
//Function: Stop
/////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnStop()
{
    // TODO: Add your control notification handler code here

    if(m_bPlaying)
    {
        Stop();
    }
    if(m_bConvert)
    {
       if(outFile!=NULL)
          closeWriffFiles();
       if(yuvBuf!=NULL)
       {
           free(yuvBuf);
           yuvBuf=NULL;
       }
       m_bConvert=0;

       //
    }
}
void CPlayerDlg::Stop()
{
    CButton *pButton;
    if(!m_bPlaying)
        return;
    KillTimer(PLAY_TIMER);
    if(Hik_PlayM4_StopSound())
    {
        m_bSound=FALSE;
        pButton = (CButton *)GetDlgItem(IDC_SOUND);
        pButton->SetIcon(m_hSoundStopIcon);
    }
    //continue before stop.Add by lgl at 9-19;
    m_bPause=FALSE;

    //stop
    m_bPlaying = !Hik_PlayM4_Stop(PORT);
    if(!m_bPlaying)
    {
        SetStopState();
        if(m_bStreamType)
            ResetEvent(m_hEventInput);
    }

    
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.