我正在将 Windows Phone 8 应用程序移植到 Windows 8,似乎 Media Engine 库的工作方式有所不同。
这是我在 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()
抛出 0xc00d36e6 异常 (MF_E_ATTRIBUTENOTFOUND)。
我尝试搜索 MP3 的媒体引擎播放示例,但只能找到视频播放示例。
有什么想法吗?
最佳答案
我找出了缺失的属性。我必须添加 MF_MEDIA_ENGINE_AUDIO_CATEGORY
来指定媒体引擎实际执行的操作。这是一个适用于 WP8 和 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)
);
关于c++ - 在 Windows 8 上使用 Media Engine 播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21066711/