⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 media.cpp

📁 在windce环境下用evc开发的播放软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    //Get the audio property
    if(m_pBA != NULL)
    {
        m_pBA->get_Volume(&prop.lVolume);
        m_pBA->get_Balance(&prop.lBalance);
    }


    //Get the video property
    if(CheckVisibility() == TRUE && m_pBV != NULL)
    {        
        m_pBV->get_BitRate(&prop.lBitRate);
        m_pBV->GetVideoSize(&prop.lWidth,&prop.lHeight);        
    }


    //Get the seeking property
    if(m_pMS != NULL)
    {
        m_pMS->GetDuration(&prop.llDuration);
        m_pMS->GetAvailable(&prop.llAvailableEarliest,&prop.llAvailableLatest);
    }



    *pOutProperty = prop;


    return TRUE;
}


//------------------------------------------------------------
//Description:
//    Set the display mode.
//    When you call the function,you should call SetVideoWindow() before.
//If the parent windows (m_hWndVideo) is NULL, the display area would be set to zero.
//
//------------------------------------------------------------
BOOL CMedia::SetDisplayMode(DISPLAYMODE mode)
{

    if(m_pVW == NULL)
    {
        return FALSE;
    }

    if(m_hWndVideo == NULL)
    {
        m_pVW->put_Left(0);
        m_pVW->put_Top(0);
        m_pVW->put_Width(0);
        m_pVW->put_Height(0);

        return FALSE;
    }

    m_DispMode = mode;

    if(mode == DISP_FULLSCREEN)
    {
        m_pVW->put_FullScreenMode(OATRUE);
    }
    else
    {
        //Restore to the normal mode
        m_pVW->put_FullScreenMode(OAFALSE);
        
        RECT rcWnd = m_rcDisp;
        if(rcWnd.left == RC_WHOLE_WINDOWN_AREA.left &&
            rcWnd.top == RC_WHOLE_WINDOWN_AREA.top &&
            rcWnd.right == RC_WHOLE_WINDOWN_AREA.right &&
            rcWnd.bottom == RC_WHOLE_WINDOWN_AREA.bottom )
        {
            GetClientRect(m_hWndVideo,&rcWnd);
        }
        LONG lWndWidth = rcWnd.right - rcWnd.left;
        LONG lWndHeight = rcWnd.bottom - rcWnd.top;

        MEDIAPROPERTY prop = {0};
        GetMediaProperty(&prop);


        if(mode == DISP_FIT || mode == DISP_NATIVE)
        {
            LONG lDispLeft,lDispTop,lDispWidth,lDispHeight;

            if(mode == DISP_NATIVE && lWndWidth >= prop.lWidth && lWndHeight >= prop.lHeight)
            {
                lDispLeft = (lWndWidth - prop.lWidth) / 2 + rcWnd.left;
                lDispTop = (lWndHeight - prop.lHeight) / 2 + rcWnd.top;
                lDispWidth = prop.lWidth ;
                lDispHeight = prop.lHeight ;
            }
            else
            {
                if(prop.lWidth * lWndHeight > lWndWidth * prop.lHeight)
                {
                    lDispWidth = lWndWidth;                
                    lDispHeight = (LONG)((float)lDispWidth / (float)prop.lWidth * prop.lHeight);
                    lDispLeft = rcWnd.left;
                    lDispTop = (lWndHeight - lDispHeight) / 2 + rcWnd.top;        
                }
                else if(prop.lWidth * lWndHeight < lWndWidth * prop.lHeight)
                {
                    lDispHeight = lWndHeight;
                    lDispWidth = (LONG)((float)lDispHeight / (float)prop.lHeight * prop.lWidth);
                    lDispLeft = (lWndWidth - lDispWidth) / 2 + rcWnd.left;
                    lDispTop = rcWnd.top;
                }
                else
                {
                    lDispWidth = lWndWidth;                
                    lDispHeight = lWndHeight;
                    lDispLeft = rcWnd.left;
                    lDispTop = rcWnd.top;
                }
            }

            



            m_pVW->put_Left(lDispLeft);
            m_pVW->put_Top(lDispTop);
            m_pVW->put_Width(lDispWidth);
            m_pVW->put_Height(lDispHeight);
        }
        else if(mode == DISP_STRETCH)
        {

            m_pVW->put_Left(rcWnd.left);
            m_pVW->put_Top(rcWnd.top);
            m_pVW->put_Width(lWndWidth);
            m_pVW->put_Height(lWndHeight);
        }
    
    }



    return TRUE;
}


//------------------------------------------------------------
//Description:
//    Set the volume.
//    When you call the function,you should call Open() before.
//
//Parameters:
//    lVolume:[in] The volume (amplitude) of the audio signal. 
//            Range is –10,000 to 0.
//    lBalance:[in]  The balance for the audio signal. Default value is 0.
//            The value from –10,000 to 10,000 indicating the stereo balance.
//
//------------------------------------------------------------
BOOL CMedia::SetVolume(LONG lVolume, LONG lBalance)
{
    if(m_pBA == NULL)
    {
        return FALSE;
    }

    if(lVolume < MIN_VOLUME && lVolume > MAX_VOLUME && lBalance < MIN_BALANCE && lBalance > MAX_BALANCE)
    {
        return FALSE;
    }

    m_pBA->put_Volume(lVolume);
    m_pBA->put_Balance(lBalance);

    return TRUE;
}




//----------------------------------------------------------------------
//Description:
//    Registers a window that will handle the notified message when a specified event occurs and some window message
//
//Parameters:
//    hWnd:[in] Handle of window to notify. Pass NULL to stop notification. 
//    wMsg:[in] Window message to be passed as the notification. 
//    lInstanceData:[in] Value (instance data) to be passed as the lParam parameter for the lMsg message.
//
//Remarks:
//    When the notified window receive the wMsg as the notification, you could get the event code.
//    The follow codes show that process:
//
//        //"WM_GRAPHNOTIFY" is the user-define notified message
//        case WM_GRAPHNOTIFY:
//        {
//            LONG evCode,evParam1,evParam2;
//
//            //"m_pMedia" is the instance of the CMedia
//            if(m_pMedia->GetEvent(&evCode,&evParam1,&evParam2) == TRUE)
//            {                
//                //Check the event code
//                if(evCode == EC_COMPLETE)
//                {
//                    //Do something
//                }
//            }
//            return 0;
//        } 
//
//    The event code is as follow:
// EC_ACTIVATE                     An audio or video renderer is losing or gaining activation.  
// EC_BUFFERING_DATA               The buffering status is changing.  
// EC_CLOCK_CHANGED                The filter graph has changed from one reference clock to another.  
// EC_COMPLETE                     All data has been rendered.  
// EC_DRM_LEVEL                    Notifies when content protected by digital rights management (DRM) requests some form of analog content protection. 
// EC_END_OF_SEGMENT               Notifies that a segment end has been reached.  
// EC_ERROR_STILLPLAYING           At least one call to Run failed in an active filter graph. 
//                                    The current state of any underlying filter graph or graphs is indeterminate; they might be running, but some are almost certainly not. 
// EC_ERRORABORT                   An error forced the termination of a requested operation.  
// EC_FULLSCREEN_LOST              The video renderer is switching out of full-screen mode.  
// EC_NEED_RESTART                 The current graph must be stopped and restarted.  
// EC_NOTIFY_WINDOW                Pass the window handle around during pin connection.  
// EC_OLE_EVENT                    A filter is passing a text string to the application.  
// EC_OPENING_FILE                 The open file status is changing.  
// EC_PALETTE_CHANGED              The video palette has changed.  
// EC_QUALITY_CHANGE               The playback quality has changed.  
// EC_REPAINT                      A repaint is required.  
// EC_SEGMENT_STARTED              Notifies that a new segment has been started.  
// EC_SHUTTING_DOWN                The filter graph is starting to shut down. 
//                                    DirectShow passes this notification to any plug-in distributors that support the IMediaEventSink interface. 
// EC_STARVATION                   One of the filters (usually a parser or file source filter) is not receiving enough data. 
//                                    By default, the filter graph manager will pause all running filters and then return to normal operation when enough data is available. 
// EC_STREAM_CONTROL_STARTED       The starting reference time from an earlier call to IAMStreamControl::StartAt passed.  
// EC_STREAM_CONTROL_STOPPED       The stopping reference time from an earlier call to IAMStreamControl::StopAt passed.  
// EC_STREAM_ERROR_STILLPLAYING    The stream is still playing, but should not be playing.  
// EC_STREAM_ERROR_STOPPED         The stream has stopped, but should not have stopped.  
// EC_TIME                         The requested reference time occurred.  
// EC_USERABORT                    A user has forced the termination of a requested operation.  
// EC_VIDEO_SIZE_AR_CHANGED        The size or aspect ratio of the native video has changed.  
// EC_VIDEO_SIZE_CHANGED           The size of the native video has changed.  
// EC_WINDOW_DESTROYED             The video renderer's filter is being removed or destroyed.  
//
//
//
//    DirectShow passes the following messages to the window specified by the hWnd parameter, 
//if and when the application generates them: 
// WM_KEYDOWN 
// WM_KEYUP 
// WM_LBUTTONDBLCLK 
// WM_LBUTTONDOWN 
// WM_LBUTTONUP 
// WM_MBUTTONDBLCLK 
// WM_MBUTTONDOWN 
// WM_MBUTTONUP 
// WM_MOUSEACTIVATE 
// WM_MOUSEMOVE 
// WM_RBUTTONDBLCLK 
// WM_RBUTTONDOWN 
// WM_RBUTTONUP 
//-----------------------------------------------------------------------------
BOOL CMedia::SetNotifyWindow(HWND hWnd, UINT wMsg,long lInstanceData)
{


    if(m_pME == NULL)
    {
        return FALSE;
    }

    HRESULT hr;
    hr = m_pME->SetNotifyWindow((OAHWND)hWnd,wMsg,lInstanceData);
    if(FAILED(hr))
    {
        return FALSE;
    }

    if(CheckVisibility() == TRUE && m_pVW != NULL)
    {
        hr = m_pVW->put_MessageDrain((OAHWND)hWnd);
    }
    

    
    
    return SUCCEEDED(hr);
}


//----------------------------------------------------------------------
//Description:
//    This method retrieves the notification event. 
//
//-----------------------------------------------------------------------
BOOL CMedia::GetEvent(LONG *plEvCode, LONG *plParam1, LONG *plParam2)
{
    if(m_pME == NULL)
    {
        return FALSE;
    }

    LONG evCode, evParam1, evParam2;    

    if(SUCCEEDED(m_pME->GetEvent(&evCode, &evParam1, &evParam2, 0)) == TRUE)
    {
        *plEvCode = evCode;
        *plParam1 = evParam1;
        *plParam2 = evParam2;

        // Spin through the events
        m_pME->FreeEventParams(evCode, evParam1, evParam2);        
    }
    else
    {
        return FALSE;
    }
    

    return TRUE;
}


//----------------------------------------------------------------------
//Description:
//    This method sets a new playback rate. 
//
//Parameters
//    dRate:[in] New rate, where 1 is the normal rate, 2 is twice as fast, and so on. 

//-----------------------------------------------------------------------
BOOL CMedia::SetRate(double dRate)
{
    if(m_pMS == NULL)
    {
        return FALSE;
    }
    return SUCCEEDED(m_pMS->SetRate(dRate));
}


//----------------------------------------------------------------------
//Description:
//    This method retrieves the current rate.
//
//Parameters:
//    pdRate:[out] The rate
//-----------------------------------------------------------------------
BOOL CMedia::GetRate(double *pdRate)
{
    if(m_pMS == NULL)
    {
        return FALSE;
    }

    return SUCCEEDED(m_pMS->GetRate(pdRate));

}

//----------------------------------------------------------------------
//Description:
//    This method retrieves the current position in terms of the total length of the media stream
//
//Parameters:
//    pllPos:[out]Current position.
//-----------------------------------------------------------------------
BOOL CMedia::GetPositionCurrent(LONGLONG *pllPos)
{
    if(m_pMS == NULL)
    {
        return FALSE;
    }

    if(m_dwCapability & AM_SEEKING_CanGetCurrentPos == 0)
    {
        return FALSE;
    }

    return SUCCEEDED(m_pMS->GetCurrentPosition(pllPos));
}

//----------------------------------------------------------------------
//Description:
//    This method sets current positions
//
//Parameters:
//    llPos:[in]Start position if stopped, or position from which to continue if paused. 
//-----------------------------------------------------------------------
BOOL CMedia::SetPositionCurrent(LONGLONG llPos)
{
    if(m_pMS == NULL)
    {
        return FALSE;
    }

    LONGLONG llCur = 0;
    if(GetPositionCurrent(&llCur) == TRUE)
    {
        if((llCur > llPos) && (m_dwCapability & AM_SEEKING_CanSeekBackwards == 0))
        {
            return FALSE;
        }
        else if((llCur < llPos) && (m_dwCapability & AM_SEEKING_CanSeekForwards == 0))
        {            
            return FALSE;            
        }
        else if(llCur == llPos)
        {
            //It's the current positon, needn't set
            return TRUE;
        }
    }
    else if((m_dwCapability & AM_SEEKING_CanSeekBackwards == 0) || (m_dwCapability & AM_SEEKING_CanSeekForwards == 0))
    {
        return FALSE;
    }


    return SUCCEEDED(m_pMS->SetPositions(&llPos,AM_SEEKING_AbsolutePositioning,NULL,AM_SEEKING_NoPositioning));
}


//----------------------------------------------------------------------
//Description:
//    This method get current display mode
//
//----------------------------------------------------------------------
DISPLAYMODE CMedia::GetDisplayMode()
{
    return m_DispMode;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -