IGraphBuilder *pGraph->RenderFile(argv[1], NULL); //L"C:////Example.avi", NULL);

本文展示了一个使用DirectShow API创建简单文件播放器的示例代码。通过初始化COM库、创建过滤器图表管理器并设置接口,实现了指定文件的媒体播放功能。此示例为开发者提供了DirectShow的基本用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#ifndef  UNICODE
#define  UNICODE
#endif
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>			// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <streams.h>

//void main(int n, TCHAR **argv) 
void _tmain(int n, TCHAR **argv) 
{ 
	if(n!=2)
	{
		printf("No file input!\n"); 
		return;
	}
    IGraphBuilder *pGraph = NULL; 
    IMediaControl *pControl = NULL; 
    IMediaEvent   *pEvent = NULL;

    // Initialize the COM library. 
    HRESULT hr = CoInitialize(NULL); 
    if (FAILED(hr)) 
    { 
        printf("ERROR - Could not initialize COM library"); 
        return; 
    }

    // Create the filter graph manager and query for interfaces. 
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&pGraph); 
    if (FAILED(hr)) 
    { 
        printf("ERROR - Could not create the Filter Graph Manager."); 
        return; 
    }

    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); 
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

    // Build the graph. IMPORTANT: Change this string to a file on your system. 
    hr = pGraph->RenderFile(argv[1], NULL);  //L"C:////Example.avi", NULL); 
	//hr = pGraph->RenderFile(L"C:\\DX90SDK\\Samples\\Media\\CLOCKTXT.avi", NULL); 
    if (SUCCEEDED(hr)) 
    { 
        // Run the graph. 
        hr = pControl->Run(); 
        if (SUCCEEDED(hr)) 
        { 
            // Wait for completion. 
            long evCode; 
            pEvent->WaitForCompletion(INFINITE, &evCode);

            // Note: Do not use INFINITE in a real application, because it 
            // can block indefinitely. 
        } 
    } 
    pControl->Release(); 
    pEvent->Release(); 
    pGraph->Release(); 
    CoUninitialize(); 
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值