Share via


Show Video

The following code examples demonstrate how to add a window to receive video. The operations in the Initialize RTC code example must be performed before using these examples.

Note  These examples do not contain error checking or releases appropriate for real code.

C++ Code Example

//
// Code Example 1: Autoshow the video window when the video  
//                 stream starts.    
//    
IVideoWindow    *pIRecvVideo; 

// Get the video receive interface for the preview video window
// and specify the RTCVD_PREVIEW enumeration value.

hr = pIRTCClient->get_IVideoWindow( RTCVD_RECEIVE , &pIRecvVideo );

// If (hr != S_OK), process the error here.

// This will make the video stream visible as soon as the 
// stream starts.
hr = pIRecvVideo->put_AutoShow(TRUE);

// If (hr != S_OK), process the error here.


//  
// Code Example 2: Specify the size and location of the
//                 video window.
//   
//
//  In the IRTCMediaEvent RTC_MEDIA event handler method
//
.....

case RTCMET_STARTED:
{
    // Get the video receive interface for the preview video window
    // and specify the RTCVD_PREVIEW enumeration value.

    IVideoWindow    *pIRecvVideo  = NULL

    // Get the Ivideo window interface. 
    hr = pIRTCClient->get_IVideoWindow( RTCVD_RECEIVE,
                                        &pIRecvVideo );

    // If (hr != S_OK), process the error here.

    hr = m_pIRecvVideo->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);

    // If (hr != S_OK), process the error here.
                                        
    //
    // The m_hWnd parent window should have the  WS_CLIPCHILDREN 
    // style defined.
    //

    hr = m_pIRecvVideo->put_Owner((OAHWND) m_hWnd);

    // If (hr != S_OK), process the error here.
        
    // Get the handle of the video window rectangle/control area 
    // needed to get the size and coordinates of the video area.
    RECT  rectPos; 

    //
    // Insert code to get the rectangle coordinates here.
    //
....

    // Set the video window coordinates.
    hr = m_pIRecvVideo->SetWindowPosition( rectPos.left,
                                           rectPos.top, 
                                           rectPos.right, 
                                           rectPos.bottom );

    // If (hr != S_OK), process the error here.

    // Show the video window.
    hr = m_pIRecvVideo->put_Visible(TRUE);

    // If (hr != S_OK), process the error here.
    ....

    break;

}

// Clean up the video window and set to NULL.
case RTCMET_STOPPED:
{
    // DShow IVideoWindow SDK 
    // Note: Do not close the video window without 
    // releasing the video or removing ownership of the
    // video window from the parent window.

    m_pIRecvVideo->put_Visible(FALSE);
    m_pIRecvVideo->put_Owner(NULL);   

    m_pIRecvVideo->Release();
    m_pIRecvVideo = NULL;

    break;
}
....

Visual Basic Code Example

'
' Code Example 1: Autoshow the video window when the 
'                video stream starts.
'
' Set the error handling routine here. 
' On Error GoTo MyErrorRoutine 

'Declare the IVideoWindow object for the incoming video stream.
Private g_objVideoRecv As IVideoWindow

' Get the IVideoWindow objects for the incoming video stream.
' This object can be set even before a session is created.
Set g_objVideoRecv = g_objRTCClient.IVideoWindow(RTCVD_RECEIVE)

' Make the video stream visible as soon as the stream starts.
g_objVideoRecv.AutoShow = True


'
' Code Example 2: Specify the size and location of the video window.
' 
' Part of a Select Case in a media event handler    
Case RTCMET_STARTED
    ' Remove the frame around the windows.
    g_objVideoRecv.WindowStyle = WS_CHILD Or WS_CLIPSIBLINGS

    ' Set the picture control as the parent so that video 
    ' appears within the control.
     g_objVideoRecv.Owner = picVideo.hWnd 

    ' Resizing and positioning. For more information,
    ' search the SDK for IVideoInterface.
    Call g_objVideoRecv.SetWindowPosition(0, 0, 200, 160)
    g_objVideoRecv.Visible = 1

    ' DShow IVideoWindow SDK
    ' Note: Do not close the window without releasing the video or
    'removing ownership of the video window from the parent window.
Case RTCMET_STOPPED
    g_objVideoRecv.Visible = 0
    g_objVideoRecv.Owner = 0
.....

End Select