directx with mp3

does anyone know how to play an mp3 with directx sdk.. i have version 8... im wanting this for background music for a game... dont know if that changes anything


Comments

  • You can play mp3s with DirectShow 8.0.
    Sunlight, from the Windows Programming board posted this:

    An MP3 player, in 28 lines of code (excluding comments):



    #include
    #include
    #include
    #include

    #pragma comment(lib, "ole32.lib")
    #pragma comment(lib, "amstrmid.lib")

    IGraphBuilder *g_pGraphBuilder;
    IMediaControl *g_pMediaControl;
    IBaseFilter *pSource;
    IPin *pPin;

    int main(void)
    {
    // Initialise COM, so that we can use CoCreateInstance.
    ::CoInitialize(NULL);

    // Create an IGraphBuilder object, through which
    // we will create a DirectShow graph.
    CoCreateInstance(CLSID_FilterGraph, NULL,
    CLSCTX_INPROC, IID_IGraphBuilder,
    (void **)&g_pGraphBuilder);

    // Get the IMediaControl Interface
    g_pGraphBuilder->QueryInterface(IID_IMediaControl,
    (void **)&g_pMediaControl);

    // Add the new source filter to the graph.
    g_pGraphBuilder->AddSourceFilter(L"x.mp3", L"x.mp3", &pSource);

    // Get the first output pin of the new source filter. Audio sources
    // typically have only one output pin, so for most audio cases finding
    // any output pin is sufficient.
    pSource->FindPin(L"Output", &pPin);

    // We have the new output pin. Render it
    g_pGraphBuilder->Render(pPin);

    pPin->Release();

    // Start the graph
    g_pMediaControl->Run();

    printf("Playing x.mp3, press any key to stop...
    ");

    getch();

    g_pMediaControl->Stop();

    pSource->Release();
    g_pMediaControl->Release();
    g_pGraphBuilder->Release();

    return 0;
    }

    This might be usefull.

    ~Andrew Clark


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion