用于播放视频的DShow示例代码无法播放视频MSDN C ++

时间:2015-10-02 21:11:51

标签: c++ video visual-studio-2013 directx directshow

我指的是提供here的示例程序来运行视频文件,使用DShow以我的情况mp4格式运行

请参阅完整代码:

#include <dshow.h>
#pragma comment (lib, "strmiids.lib")
void main(void)
{
    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(L"C:\\Example.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();
}

然而,当我构建程序时,构建是成功的,但是当我运行它时,控制台窗口会弹出并在一秒钟内消失。

我提到同一页面上的评论和许多其他人面临同样的问题。然而,一些人能够成功运行该计划。

我做错了什么?

这是我选择的项目类型吗?我正在选择win32 console application。我应该选择别的吗?或者还有别的我做错了吗?

0 个答案:

没有答案