Answered by:
MFCreateMediaSession not supported for Metro apps?

Question
-
I'm learning Media Foundation and would like to use it from my own Metro apps. Unfortunately, MFCreateMediaSession is not supported for Metro apps. Why is that? How would a Metro app create a media session to, say, play a stream of PCM audio generated on the fly by the app?
- Edited by rwalters Thursday, April 19, 2012 12:57 AM
Wednesday, April 18, 2012 1:43 AM
Answers
-
Hello rwalters,
Here are two options for you:
1) Use WASAPI and pump your synthesized PCM audio directly to the audio manager (preferred)
2) Create a custom source that can plug into the Media Foundation Media Engine
Either approach will work as expected. You will need to carefully review each method and compare them against your software requirements. For most synthesized audio scenarios, using the WASAPI is recommended.
Win32 and COM for Metro style apps (multimedia)
http://msdn.microsoft.com/en-us/library/windows/apps/hh452756.aspxReal-time communication sample
http://code.msdn.microsoft.com/windowsapps/Simple-Communication-Sample-eac73290I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by James Dailey - MSFTMicrosoft employee, Moderator Thursday, April 19, 2012 9:28 PM
- Unproposed as answer by rwalters Monday, April 23, 2012 5:10 PM
- Marked as answer by rwalters Monday, April 23, 2012 10:00 PM
Thursday, April 19, 2012 9:23 PMModerator -
Hello rwalters,
Here are the answers to your questions:
Q. How do I even get a handle to an audio device when IMMDevice isn't supported for Metro style apps?
A. Code listed below:Platform::String^ id = Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId(Windows::Media::Devices::AudioDeviceRole::Console ); Microsoft::WRL::ComPtr<IAudioClient> pAudioClient = NULL; ActivateAudioInterface( id->Data(), __uuidof( IAudioClient ), (void**)&pAudioClient );
Q. ...it seems the approach for play/record would be the following -- have I got it right so far?
A. Yes this seems like a reasonable approach.I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by James Dailey - MSFTMicrosoft employee, Moderator Monday, April 23, 2012 9:21 PM
- Marked as answer by rwalters Monday, April 23, 2012 10:15 PM
Monday, April 23, 2012 9:21 PMModerator
All replies
-
Hello,
Did you want to use MFCreateMediaSession to create playlist?
If so, you can use Windows.Media.Playlists namespace to instead of it
http://msdn.microsoft.com/library/windows/apps/BR206938There is the sample codes
http://code.msdn.microsoft.com/windowsapps/Playlist-sample-3d80daeeBest regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Thursday, April 19, 2012 7:32 AM -
No, I don't want to create a playlist. I want to play a stream of PCM audio generated on the fly by the app. This means my app creates the audio samples using an algorithm, and it runs continuously. There is no file, no audio format, just plain audio samples.Thursday, April 19, 2012 6:53 PM
-
Hello rwalters,
Here are two options for you:
1) Use WASAPI and pump your synthesized PCM audio directly to the audio manager (preferred)
2) Create a custom source that can plug into the Media Foundation Media Engine
Either approach will work as expected. You will need to carefully review each method and compare them against your software requirements. For most synthesized audio scenarios, using the WASAPI is recommended.
Win32 and COM for Metro style apps (multimedia)
http://msdn.microsoft.com/en-us/library/windows/apps/hh452756.aspxReal-time communication sample
http://code.msdn.microsoft.com/windowsapps/Simple-Communication-Sample-eac73290I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by James Dailey - MSFTMicrosoft employee, Moderator Thursday, April 19, 2012 9:28 PM
- Unproposed as answer by rwalters Monday, April 23, 2012 5:10 PM
- Marked as answer by rwalters Monday, April 23, 2012 10:00 PM
Thursday, April 19, 2012 9:23 PMModerator -
Thanks James, but I find the "Win32 and COM for Metro style apps (multimedia)" reference confusing and unhelpful. It's really only a list of functions that I can call from a Metro app. What about the ones I can't?
More specific questions on the two options proposed:
1) WASAPI: I'm missing one crucial piece in my understanding -- how to do the initial activation/instantiation of the required objects to access audio devices. How do I even get a handle to an audio device when IMMDevice isn't supported for Metro style apps?
2) Media Foundation Media Engine: from studying the real-time communication sample, it seems the approach for play/record would be the following -- have I got it right so far?
- Playback: Use Windows.Media.MediaExtensionManager to register a scheme (in the example, it's "stsp://") handler which creates a custom source whenever a URL with this scheme is navigated to.
- Recording: Implement a custom sink and use Windows.Media.Capture.MediaCapture.StartRecordToCustomSinkAsync to capture media to it.
- Edited by rwalters Thursday, April 19, 2012 10:59 PM Expanded upon original post, added more specific questions
Thursday, April 19, 2012 10:13 PM - Playback: Use Windows.Media.MediaExtensionManager to register a scheme (in the example, it's "stsp://") handler which creates a custom source whenever a URL with this scheme is navigated to.
-
I'm unproposing as answer, for now, to get more attention. Option #1 was sufficiently vague, given nobody seems to know how to do it in a Metro app (no examples, factories and interfaces such as IMMDevice not available to Metro apps, etc.) I'll gladly mark it as an answer again if I could get clarification. Thanks!Monday, April 23, 2012 5:13 PM
-
Hello rwalters,
Here are the answers to your questions:
Q. How do I even get a handle to an audio device when IMMDevice isn't supported for Metro style apps?
A. Code listed below:Platform::String^ id = Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId(Windows::Media::Devices::AudioDeviceRole::Console ); Microsoft::WRL::ComPtr<IAudioClient> pAudioClient = NULL; ActivateAudioInterface( id->Data(), __uuidof( IAudioClient ), (void**)&pAudioClient );
Q. ...it seems the approach for play/record would be the following -- have I got it right so far?
A. Yes this seems like a reasonable approach.I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by James Dailey - MSFTMicrosoft employee, Moderator Monday, April 23, 2012 9:21 PM
- Marked as answer by rwalters Monday, April 23, 2012 10:15 PM
Monday, April 23, 2012 9:21 PMModerator -
Thanks for the code example! Where can I learn more about ActivateAudioInterface()? I can't seem to find it in the MSDN or Dev Center. The only hits when I search for it are here in the forums...Monday, April 23, 2012 9:45 PM
-
I agree that is a big problem that we are trying to fix.
-James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
Friday, April 27, 2012 12:33 AMModerator -
Bumping this. I'm working on a WinRT component in C++. Trying to use ActivateAudioInterface results in an unresolved symbol. What am I doing wrong?Friday, May 4, 2012 8:50 PM
-
Hello Tom,
Try "mmdeviceapi.h". If that doesn't work let me know.
-James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
Monday, May 7, 2012 11:06 PMModerator -
I'm newbie in this section, and I have another questions about SimpleCommunication sample and custom media sink:
- Can I get each picture in video stream while it is recording?
- Can I change framerate and resolution of video stream while it is recording to custom media sink?
- If I can get pictures from the video stream, can I edit it and fill it again in video stream?
Thanks
- Edited by CuongNC Wednesday, October 10, 2012 7:26 AM
Tuesday, October 9, 2012 12:21 PM