C#視頻監控系列(12):H264播放器——播放錄影檔案

來源:互聯網
上載者:User

前言

本章主要實現播放海康錄影檔案,更多播放器說明可以參考《Hikvision H264播放器編程指南V4.8》。

先來一張簡單的效果圖

以下幾個VC++ 代碼 片段:

CPlayerDlg::OnInitDialog()

    Hik_PlayM4_SetVolume(PORT,m_SoundSlider.GetPos());

    // 其他代碼

    //set the capture picture call back function;
    Hik_PlayM4_SetDisplayCallBack(PORT,DisplayCBFun);
    //set the wave audio call back funtion;
    Hik_PlayM4_SetAudioCallBack(PORT,WaveCBFun, (long)this);

    // 其他代碼

    Hik_PlayM4_SetEncTypeChangeCallBack(PORT,funEncChange,(long)this);
#if (WINVER > 0x0400)
    //If do not support multi monitor,may not call!
    Hik_PlayM4_InitDDrawDevice();
    Hik_PlayM4_SetDDrawDevice(PORT,0);
#endif
    //Test adapter Capability;
    TestCapability(0);
    Hik_PlayM4_SetFileEndMsg(PORT,m_hWnd,WM_FILE_END);
    Hik_PlayM4_SetEncChangeMsg(PORT,m_hWnd,WM_ENC_CHANGE);
    if(m_strPlayFileName.Compare(""))
    {
        if(m_bStreamType)
            OpenStream();
        else
            OpenFile();
    }


          CPlayerDlg::OpenFile()

    Hik_PlayM4_SetFileRefCallBack (PORT,FileRefDone,(DWORD)this);
    Hik_PlayM4_SetVerifyCallBack(PORT, 0, 0xffffffff, VerifyFun, (DWORD) this);// verify the whole file;
    if(!Hik_PlayM4_OpenFile(PORT,m_strPlayFileName.GetBuffer(m_strPlayFileName.GetLength())))
    {
        m_strPlayFileName="";
        CString csError;
        csError.Format("Open file failed(%d)",Hik_PlayM4_GetLastError(PORT));
        MessageBox(csError);
        return ;
    }
    SetOpenState();
    m_nMaxFileTime=Hik_PlayM4_GetFileTime(PORT);
    if(!m_nMaxFileTime)
    {
        MessageBox("File seconds is zero");
        return;
    }
    m_nTotalHour=m_nMaxFileTime/3600;
    m_nTotalMinute=(m_nMaxFileTime%3600)/60;
    m_nTotalSecond=m_nMaxFileTime%60;
    m_nTotalFrames=Hik_PlayM4_GetFileTotalFrames(PORT);
    numFrames=m_nTotalFrames;
    //If you want to change the display buffer.Do hear!
    //Hik_PlayM4_SetDisplayBuf(PORT,25);
    Play();

          CPlayerDlg::Play()

    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);

    }

          CPlayerDlg::SetOpenState()

    Hik_PlayM4_GetPictureSize (PORT,&m_nWidth,&m_nHeight);

    Hik_PlayM4_SetOverlayMode(PORT,TRUE,RGB(255,0,255));

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.