How to play ogg Vorbis files using IGraphBuilder

I need to write a program that can play .ogg Vorbis file with the help of IGraphBuilder or any other windows API directly (in C++/win32 API)?

I tried with IGraphBuilder but that is not working for me. Sample code:

IMediaControl *pControl = NULL;
IGraphBuilder *pGraph= NULL;
IMediaEventEx *pEvent= NULL;
IMediaPosition *pMediaPosition= NULL;

hr = ::CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
                        IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr)) {
    return false;

hr = pGraph->AddFilter(pFilter, L"Out");
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pGraph->QueryInterface(IID_IMediaPosition, (void**)&pMediaPosition);

// Build the graph.
hr = pGraph->RenderFile(mFilePath.c_str()/*"C:\\sample.ogg file"*/, NULL);

/* here hr = 0x80040265 so SUCCEEDED(hr) didnt allow it to enter in if condition*/
if (SUCCEEDED(hr)) {
    // Run the graph.
    hr = pControl->Run();
    if (SUCCEEDED(hr)) {
        // Wait for completion.
        long evCode;
        pEvent->WaitForCompletion(INFINITE, &evCode);

// Clean up in reverse order.
pGraph = NULL;


NOTE: Above statement hr = pGraph->RenderFile() returned the hr = 0x80040265 and condition if (SUCCEEDED(hr)) doesnt allow to play it.

If I dont use this condition then pControl->Run() gets executed with return ID_OK. But nothing played with speaker. Please suggest the solution/method.


Pay attention to HRESULT error codes; they mean something. MSDN is often helpful with function-specific error codes like the one you got. (With enough COM programming you'll be able to recognize common ones like E_INVALIDARG by sight.) If not, you can use your header files to pinpoint potential error codes. HRESULTs have a specific format; learn it!

In the case of IGraphBuilder::RenderFile(), that HRESULT maps to VFW_E_UNSUPPORTED_STREAM, which basically means your setup does not support playing Ogg Vorbis files. You will need to install a filter that allows DirectShow to play Ogg Vorbis files, such as the official one from Xiph.Org.


 ? Record voice with Java
 ? Problem encoding wav into ogg vorbis
 ? Adding ogg vorbis encoding to my project
 ? Java - from short to byte[2] using LITTLE_ENDIAN
 ? Java: Independently Capturing Audio From 2 Different Mic Inputs
 ? audioread() or waveread() of matlab in java
 ? Ogg audio file clicks upon looping - LIBGDX
 ? Ogg audio file clicks upon looping - LIBGDX
 ? Ogg audio file clicks upon looping - LIBGDX
 ? Audio Clip won't loop continuously