IWMEncDataView::Stop
The Stop method stops displaying a specific media stream.
Syntax
HRESULT Stop(
DWORD dwStreamCookie
);
Parameters
dwStreamCookie
[in] DWORD containing the ID of the stream.
Return Values
If the method succeeds, it returns S_OK. If it fails, it supports the IErrorInfo interface and returns an HRESULT error code.
Example Code
// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include "wmencode.h"
#include "wmencvu.h"
// Declare variables.
HRESULT hr;
IWMEncoder* pEncoder;
IWMEncDataView* pPreview;
IWMEncDataViewCollection* pPreviewColl;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSource* pAudSrc;
IWMEncSource* pVidSrc;
IWMEncProfileCollection* pProColl;
IWMEncProfile* pPro;
long lCount;
int i;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder,
(void**) &pEncoder);
}
// Retrieve a pointer to an IWMEncSourceGroupCollection
// interface.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}
// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}
// Add a video and an audio source to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}
// Identify the capture cards.
if ( SUCCEEDED( hr ) )
{
hr = pVidSrc->SetInput(CComBSTR("DEVICE://Default_Video_Device"));
}
if ( SUCCEEDED( hr ) )
{
hr = pAudSrc->SetInput(CComBSTR("DEVICE://Default_Audio_Device"));
}
// Choose a profile from the collection.
CComBSTR bstrName = NULL;
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_ProfileCollection(&pProColl);
}
if ( SUCCEEDED( hr ) )
{
hr = pProColl->get_Count(&lCount);
}
for (i=0; i<lCount; i++)
{
if ( SUCCEEDED( hr ) )
{
hr = pProColl->Item(i, &pPro);
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_Name(&bstrName);
}
if (_wcsicmp(bstrName,CComBSTR("Windows Media Video 8 for Local Area Network (384 Kbps)"))==0)
{
// Set the profile in the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->put_Profile(CComVariant(pPro));
}
break;
}
}
// Retrieve a pointer to a preview object.
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance( CLSID_WMEncPreview,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncDataView,
(void**)&pPreview);
}
// Retrieve the preview collection.
if ( SUCCEEDED( hr ) )
{
hr = pVidSrc->get_PreviewCollection( &pPreviewColl );
}
// Add the preview object to the data view collection. If you set the
// cookie to -1, the encoding process automatically generates a unique
// cookie.
long lCookie = -1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Add( pPreview, &lCookie);
}
// Continue configuring the encoding session.
// Initialize the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}
// Create a parent window for the preview object, and specify the window
// settings for the encoding session. For instance, you can create a
// window by using the Win32 API function CreateWindow() and pass the
// window handle retrieved from this function to the
// SetViewSetting() method.
// Windows Media Encoder embeds the preview window in the parent window.
// If you do not create a parent window and specify the display
// settings, Windows Media Encoder creates a default window for the
// preview.
HWND hWnd;
if ( SUCCEEDED( hr ) )
{
hr = pPreview->SetViewSetting((DWORD) lCookie,
sizeof(hWnd),
(BYTE*)&hWnd);
}
// Start the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
// Start viewing the stream in a pop-up window.
if ( SUCCEEDED( hr ) )
{
hr = pPreview->Start(lCookie);
}
// When finished, stop the preview.
if ( SUCCEEDED( hr ) )
{
hr = pPreview->Stop(lCookie);
}
// Stop the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Stop();
}
// Release pointers.
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
if ( pPreview )
{
pPreview->Release();
pPreview = NULL;
}
if ( pPreviewColl )
{
pPreviewColl->Release();
pPreviewColl = NULL;
}
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pAudSrc )
{
pAudSrc->Release();
pAudSrc = NULL;
}
if ( pVidSrc )
{
pVidSrc->Release();
pVidSrc = NULL;
}
if ( pProColl )
{
pProColl->Release();
pProColl = NULL;
}
if ( pPro )
{
pPro->Release();
pPro = NULL;
}
Requirements
Header: wmencvu.h
Library: wmprevu.dll
See Also