none
MFCreateMediaSession not supported for Metro apps?

    Pregunta

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

    • Editado rwalters jueves, 19 de abril de 2012 0:57
    miércoles, 18 de abril de 2012 1:43

Respuestas

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

    jueves, 19 de abril de 2012 21:23
    Moderador
  • 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/

    lunes, 23 de abril de 2012 21:21
    Moderador

Todas las respuestas

  • 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

    jueves, 19 de abril de 2012 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.
    jueves, 19 de abril de 2012 18: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/

    jueves, 19 de abril de 2012 21:23
    Moderador
  • 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.
    • Editado rwalters jueves, 19 de abril de 2012 22:59 Expanded upon original post, added more specific questions
    jueves, 19 de abril de 2012 22: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!
    lunes, 23 de abril de 2012 17: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/

    lunes, 23 de abril de 2012 21:21
    Moderador
  • 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...
    lunes, 23 de abril de 2012 21: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/

    viernes, 27 de abril de 2012 0:33
    Moderador
  • 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?
    viernes, 04 de mayo de 2012 20: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/

    lunes, 07 de mayo de 2012 23:06
    Moderador
  • 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




    • Editado CuongNC miércoles, 10 de octubre de 2012 7:26
    martes, 09 de octubre de 2012 12:21