VC 如何使用 VLC 來播放 視訊串流 @ 071's blog :: 隨意窩 Xuite日誌
    1. 沒有新回應!
  • 201309091026VC 如何使用 VLC 來播放 視訊串流

    要用VC 去使用VLC元件會用到下列的vlccontrol.h/cpp , CTest_VLCDlg會使用到它並宣告為LiveView,在建構式時將其設為NULL, 而另外有二個按鈕來控制 播放或停止 的功能, IDC_EDIT_IP_ADDRESS文字控制項存放 rtsp url的位置 (ex: rtsp://192.168.81.241/stream1)

    void CTest_VLCDlg::OnBnClickedOk()
    {
     // TODO: 在此加入控制項告知處理常式程式碼
     //Set Vlc Position
     CRect VLCPlayerRect;
     VLCPlayerRect.top = 0;
     VLCPlayerRect.left = 0;
     VLCPlayerRect.bottom = VLCPlayerRect.top + 240;
     VLCPlayerRect.right = VLCPlayerRect.left + 320;

     //Mini Live View
     DWORD dwStyle = WS_CHILD | WS_VISIBLE ;// | BS_PUSHBUTTON
     VARIANT va;
     VariantInit(&va);

     if (!LiveView) {
     LiveView = new CVLCControl;
     LiveView->Create("VLC", "Mini Video Screen", dwStyle, VLCPlayerRect, this, 1234);
     LiveView->ShowWindow(SW_SHOW);
     }
     LiveView->SetWindowPos(&CWnd::wndBottom,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
     char caRtsp[128] = "";//"rtsp://192.168.81.241/stream1"
     GetDlgItem(IDC_EDIT_IP_ADDRESS)->GetWindowText(caRtsp,sizeof(caRtsp));
     LiveView->addTarget(caRtsp, va, 0x002+0x004, -666);
     LiveView->play();


     //OnOK();
    }


    void CTest_VLCDlg::OnBnClickedStopview()
    {
     // TODO: 在此加入控制項告知處理常式程式碼
     if (LiveView){
     LiveView->stop();
     delete LiveView;
     LiveView = NULL;
     }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    //vlccontrol.h

    #pragma once
     
    class CVLCControl : public CWnd
    {
    protected:
     DECLARE_DYNCREATE(CVLCControl)
    public:
     CLSID const& GetClsid()
     {
      static CLSID const clsid
       = { 0xe23fe9c6, 0x778e, 0x49d4, { 0xb5, 0x37, 0x38, 0xfc, 0xde, 0x48, 0x87, 0xd8 } };
      return clsid;
     }
     virtual BOOL Create(LPCTSTR lpszClassName,
      LPCTSTR lpszWindowName, DWORD dwStyle,
      const RECT& rect,
      CWnd* pParentWnd, UINT nID,
      CCreateContext* pContext = NULL)
     { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }
     
        BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
      const RECT& rect, CWnd* pParentWnd, UINT nID,
      CFile* pPersist = NULL, BOOL bStorage = FALSE,
      BSTR bstrLicKey = NULL)
     { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
      pPersist, bStorage, bstrLicKey); }
     
    // Attributes
    public:
     
    // Operations
    public:
     BOOL GetVisible();
     void SetVisible(BOOL bNewValue);
     void play();
     void pause();
     void stop();
     float GetPosition();
     void SetPosition(float newValue);
     long GetTime();
     void SetTime(long nNewValue);
     void shuttle(long seconds);
     void fullscreen();
     void playFaster();
     void playSlower();
     long GetVolume();
     void SetVolume(long nNewValue);
     void toggleMute();
     void setVariable(LPCTSTR name, const VARIANT& value);
     VARIANT getVariable(LPCTSTR name);
     void addTarget(LPCTSTR uri, const VARIANT& options, long mode, long Position);
     long GetPlaylistIndex();
     long GetPlaylistCount();
     void playlistNext();
     void playlistPrev();
     void playlistClear();
     CString GetMrl();
     void SetMrl(LPCTSTR lpszNewValue);
     BOOL GetAutoPlay();
     void SetAutoPlay(BOOL bNewValue);
     BOOL GetAutoLoop();
     void SetAutoLoop(BOOL bNewValue);
    }; .

     

    //vlccontrol.cpp

    // Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++  
          
        // NOTE: Do not modify the contents of this file.  If this class is regenerated by  
        //  Microsoft Visual C++, your modifications will be overwritten.  
      
      
    #include "stdafx.h"  
    #include "vlccontrol.h"  
      
    /////////////////////////////////////////////////////////////////////////////  
    // CVLCControl  
      
    IMPLEMENT_DYNCREATE(CVLCControl, CWnd)  
      
    /////////////////////////////////////////////////////////////////////////////  
    // CVLCControl properties  
      
    /////////////////////////////////////////////////////////////////////////////  
    // CVLCControl operations  
      
    BOOL CVLCControl::GetVisible()  
    {  
        BOOL result;  
        InvokeHelper(0x64, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetVisible(BOOL bNewValue)  
    {  
        static BYTE parms[] =  
            VTS_BOOL;  
        InvokeHelper(0x64, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             bNewValue);  
    }  
      
    void CVLCControl::play()  
    {  
        InvokeHelper(0x60020002, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::pause()  
    {  
        InvokeHelper(0x60020003, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::stop()  
    {  
        InvokeHelper(0x60020004, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    float CVLCControl::GetPosition()  
    {  
        float result;  
        InvokeHelper(0x66, DISPATCH_PROPERTYGET, VT_R4, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetPosition(float newValue)  
    {  
        static BYTE parms[] =  
            VTS_R4;  
        InvokeHelper(0x66, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             newValue);  
    }  
      
    long CVLCControl::GetTime()  
    {  
        long result;  
        InvokeHelper(0x67, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetTime(long nNewValue)  
    {  
        static BYTE parms[] =  
            VTS_I4;  
        InvokeHelper(0x67, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             nNewValue);  
    }  
      
    void CVLCControl::shuttle(long seconds)  
    {  
        static BYTE parms[] =  
            VTS_I4;  
        InvokeHelper(0x6002000a, DISPATCH_METHOD, VT_EMPTY, NULL, parms,  
             seconds);  
    }  
      
    void CVLCControl::fullscreen()  
    {  
        InvokeHelper(0x6002000b, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::playFaster()  
    {  
        InvokeHelper(0x6002000d, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::playSlower()  
    {  
        InvokeHelper(0x6002000e, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    long CVLCControl::GetVolume()  
    {  
        long result;  
        InvokeHelper(0x69, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetVolume(long nNewValue)  
    {  
        static BYTE parms[] =  
            VTS_I4;  
        InvokeHelper(0x69, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             nNewValue);  
    }  
      
    void CVLCControl::toggleMute()  
    {  
        InvokeHelper(0x60020011, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::setVariable(LPCTSTR name, const VARIANT& value)  
    {  
        static BYTE parms[] =  
            VTS_BSTR VTS_VARIANT;  
        InvokeHelper(0x60020012, DISPATCH_METHOD, VT_EMPTY, NULL, parms,  
             name, &value);  
    }  
      
    VARIANT CVLCControl::getVariable(LPCTSTR name)  
    {  
        VARIANT result;  
        static BYTE parms[] =  
            VTS_BSTR;  
        InvokeHelper(0x60020013, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms,  
            name);  
        return result;  
    }  
      
    void CVLCControl::addTarget(LPCTSTR uri, const VARIANT& options, long mode, long Position)  
    {  
        static BYTE parms[] =  
            VTS_BSTR VTS_VARIANT VTS_I4 VTS_I4;  
        InvokeHelper(0x60020014, DISPATCH_METHOD, VT_EMPTY, NULL, parms,  
             uri, &options, mode, Position);  
    }  
      
    long CVLCControl::GetPlaylistIndex()  
    {  
        long result;  
        InvokeHelper(0x60020015, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);  
        return result;  
    }  
      
    long CVLCControl::GetPlaylistCount()  
    {  
        long result;  
        InvokeHelper(0x60020016, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::playlistNext()  
    {  
        InvokeHelper(0x60020017, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::playlistPrev()  
    {  
        InvokeHelper(0x60020018, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    void CVLCControl::playlistClear()  
    {  
        InvokeHelper(0x60020019, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);  
    }  
      
    CString CVLCControl::GetMrl()  
    {  
        CString result;  
        InvokeHelper(0x6a, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetMrl(LPCTSTR lpszNewValue)  
    {  
        static BYTE parms[] =  
            VTS_BSTR;  
        InvokeHelper(0x6a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             lpszNewValue);  
    }  
      
    BOOL CVLCControl::GetAutoPlay()  
    {  
        BOOL result;  
        InvokeHelper(0x6b, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetAutoPlay(BOOL bNewValue)  
    {  
        static BYTE parms[] =  
            VTS_BOOL;  
        InvokeHelper(0x6b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             bNewValue);  
    }  
      
    BOOL CVLCControl::GetAutoLoop()  
    {  
        BOOL result;  
        InvokeHelper(0x6c, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);  
        return result;  
    }  
      
    void CVLCControl::SetAutoLoop(BOOL bNewValue)  
    {  
        static BYTE parms[] =  
            VTS_BOOL;  
        InvokeHelper(0x6c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,  
             bNewValue);  
    }  

    ip v6|日誌首頁|C 語言 巨集的使用上一篇ip v6下一篇C 語言 巨集的使用
    回應