Playing music with Media Engine on Windows 8

0

I am porting a Windows Phone 8 app to Windows 8 and it seems that Media Engine library works differently.

Here is my initialization code that works on WP8:

DX::ThrowIfFailed(
    MFStartup(MF_VERSION)
    );
ComPtr<IMFMediaEngineClassFactory> mediaEngineFactory;
ComPtr<IMFAttributes> mediaEngineAttributes;

// Create the class factory for the Media Engine.
DX::ThrowIfFailed(
    CoCreateInstance(CLSID_MFMediaEngineClassFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&mediaEngineFactory))
    );

// Define configuration attributes.
DX::ThrowIfFailed(
    MFCreateAttributes(&mediaEngineAttributes, 1)
    );

ComPtr<MediaEngineNotify> notify = Make<MediaEngineNotify>();
ComPtr<IUnknown> unknownNotify;
DX::ThrowIfFailed(
    notify.As(&unknownNotify)
    );

DX::ThrowIfFailed(
    mediaEngineAttributes->SetUnknown(MF_MEDIA_ENGINE_CALLBACK, unknownNotify.Get())
    );

// Create the Media Engine.
DX::ThrowIfFailed(
    mediaEngineFactory->CreateInstance(0, mediaEngineAttributes.Get(), &m_mediaEngine)
    );

CreateInstance() throws 0xc00d36e6 exception ( MF_E_ATTRIBUTENOTFOUND ).

I've tried to search for samples for Media Engine playback of mp3s but can only find Video Playback samples.

Any ideas?

c++
windows-8
c++-cli
directx
directx-11
asked on Stack Overflow Jan 11, 2014 by Grapes

1 Answer

3

I figured out the missing attribute. I had to add MF_MEDIA_ENGINE_AUDIO_CATEGORY to specify what M the Media Engine is actually doing. Here is an example that works for both WP8 and WIN8:

#if PLATFORM_WINDOWS8
    DX::ThrowIfFailed(
        MFStartup(MF_VERSION)
        );
#endif
    ComPtr<IMFMediaEngineClassFactory> mediaEngineFactory;
    ComPtr<IMFAttributes> mediaEngineAttributes;

    // Create the class factory for the Media Engine.
    DX::ThrowIfFailed(
        CoCreateInstance(CLSID_MFMediaEngineClassFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&mediaEngineFactory))
        );

    // Define configuration attributes.
    DX::ThrowIfFailed(
        MFCreateAttributes(&mediaEngineAttributes, 1)
        );

    ComPtr<MediaEngineNotify> notify = Make<MediaEngineNotify>();
    ComPtr<IUnknown> unknownNotify;
    DX::ThrowIfFailed(
        notify.As(&unknownNotify)
        );

    DX::ThrowIfFailed(
        mediaEngineAttributes->SetUnknown(MF_MEDIA_ENGINE_CALLBACK, unknownNotify.Get())
        );

    DWORD flags=0;

#if PLATFORM_WINDOWS8
    DX::ThrowIfFailed(
        mediaEngineAttributes->SetUINT32(MF_MEDIA_ENGINE_AUDIO_CATEGORY, AudioCategory_GameMedia)
        );
    flags = MF_MEDIA_ENGINE_AUDIOONLY | MF_MEDIA_ENGINE_REAL_TIME_MODE;
#endif

    // Create the Media Engine.
    DX::ThrowIfFailed(
        mediaEngineFactory->CreateInstance(flags, mediaEngineAttributes.Get(), &m_mediaEngine)
        );
answered on Stack Overflow Jan 11, 2014 by Grapes

User contributions licensed under CC BY-SA 3.0