none
MFCreateMediaSession not supported for Metro apps?

    질문

  • 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?

    • 편집됨 rwalters 2012년 4월 19일 목요일 오전 12:57
    2012년 4월 18일 수요일 오전 1:43

답변

  • 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.aspx

    Real-time communication sample
    http://code.msdn.microsoft.com/windowsapps/Simple-Communication-Sample-eac73290

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    2012년 4월 19일 목요일 오후 9:23
  • 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/

    2012년 4월 23일 월요일 오후 9:21

모든 응답

  • 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/BR206938

    There is the sample codes
    http://code.msdn.microsoft.com/windowsapps/Playlist-sample-3d80daee

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    2012년 4월 19일 목요일 오전 7:32
  • 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.
    2012년 4월 19일 목요일 오후 6:53
  • 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.aspx

    Real-time communication sample
    http://code.msdn.microsoft.com/windowsapps/Simple-Communication-Sample-eac73290

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    2012년 4월 19일 목요일 오후 9:23
  • 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.
    • 편집됨 rwalters 2012년 4월 19일 목요일 오후 10:59 Expanded upon original post, added more specific questions
    2012년 4월 19일 목요일 오후 10:13
  • 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!
    2012년 4월 23일 월요일 오후 5:13
  • 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/

    2012년 4월 23일 월요일 오후 9:21
  • 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...
    2012년 4월 23일 월요일 오후 9:45
  • 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/

    2012년 4월 27일 금요일 오전 12:33
  • 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?
    2012년 5월 4일 금요일 오후 8:50
  • 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/

    2012년 5월 7일 월요일 오후 11:06
  • 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




    • 편집됨 CuongNC 2012년 10월 10일 수요일 오전 7:26
    2012년 10월 9일 화요일 오후 12:21