Answered How to use WASPAI Capture in Metro style apps

  • Sonntag, 25. Dezember 2011 10:11
     
     

    Since the WASAPI is surpported in Metro style apps, I tried it:

    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 );

    WAVEFORMATEX *pDeviceFormat = NULL;

    pAudioClient->GetMixFormat( &pDeviceFormat );

    All of above are success !

    HRESULT hr = pAudioClient->Initialize( AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0,  pDeviceFormat  , NULL);

    BUT,   ***  IAudioClient::Initialize ***    failed!!!!     the Error code is ( E_ACCESSDENIED 0x80070005 ).

    BUT, if I check the "Microphone" in Package.appxmanifest -- Capabilities , the Error is 0x8000FFFF.

    Help me please !

Alle Antworten

  • Mittwoch, 28. Dezember 2011 14:07
    Moderator
     
     
    I do not see in your code where you are initializing COM.  Are you doing this?
    Jeff Sanders (MSFT)
  • Sonntag, 1. Januar 2012 10:12
     
     
    What a Strange thing! I create a new project, and check the "Microphone" in Capabilities. And now it does not return error, but it hangs in method IAudioClient::Initialize. When I stop debugging, a dialog, which askes whether to allow using the Mricophone, flashes on the screen. How can I make that dialog appear in the beginning.
  • Montag, 6. Februar 2012 13:21
     
     
    I do not see in your code where you are initializing COM.  Are you doing this?
    Jeff Sanders (MSFT)
    Hi Jeff, I has the same question, can I send you a demo? It's my email: linyehui#live.com
  • Freitag, 17. Februar 2012 22:04
    Moderator
     
     

    If you are still having this issue please let me know and I will do what I can to help.

    -James


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

  • Dienstag, 3. April 2012 20:47
     
     
    I need help here. Is the above code for windows 8? They are not compiling for me.
  • Mittwoch, 4. April 2012 00:38
     
     
    Well now, I can compile the code. But IAudioClient->initialize hangs too. I don't see the dialog to ask for permission to use the microphone either.
  • Mittwoch, 4. April 2012 20:55
     
     Beantwortet
    I figured the IAudioClient->initialize issue. Except checking the "Microphone" in Capabilities, you also need to set the permission in system settings. Start the application (comment out the hanging part of the code, just run the blank application), choose settings charm to set the permission for microphone. go back to code to uncomment the initialize code, run the application again. It should work now.
  • Samstag, 7. April 2012 00:04
    Moderator
     
     

    Just following up on this thread now that I am back in the office. Do you have everything you need? Was your previous post a good solution for you?

    -James


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

  • Donnerstag, 12. April 2012 17:22
     
     Beantwortet

    Yes, James. This problem is resolved. But I have another issue which I am still waiting for reply. Please see my thread here:

    http://social.msdn.microsoft.com/Forums/bs-Cyrl-BA/winappswithcsharp/thread/34b081ba-0c4c-49f4-8353-c915b2e26cc3

  • Donnerstag, 12. April 2012 22:50
    Moderator
     
     

    I replied on the referenced thread.

    -James


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

  • Donnerstag, 17. Mai 2012 12:24
     
      Enthält Code

    Great, this has helped!

    I have another question, concerning IAudioClient->Initialize, although it seems to work for now. The WASAPI documentation states:

    Note  In Windows 8 Consumer Preview, the first use of IAudioClient to access the audio device should be on the STA thread. Calls from an MTA thread may result in undefined behavior.

    But C++ threads are MTA by default and this doesn't seem to work:

    using namespace Windows::Foundation;
    using namespace Platform;
    
    [Threading(ThreadingModel=ThreadingModel::STA] 
    public ref class MySTAClass
    {
    };

    Intellisense declares Error: Attributes are not allowed here.

    • Bearbeitet Oslik Donnerstag, 17. Mai 2012 12:33
    •  
  • Freitag, 18. Mai 2012 00:55
    Moderator
     
     

    Make sure it is initialized and used on the main UI thread if you are using XAML in C++.

    -James


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

  • Montag, 4. Juni 2012 08:28
     
     

    Hi,

    Following several threads on how to use WASAPI in Metro Style Apps, I still have many issues understanding how it works:

    What is "ActivateAudioInterface" ? never found it in MSDN except forums, and can't make it work either.

    Thanks,
    ~Jerome

  • Montag, 11. Juni 2012 21:44
    Moderator
     
     Beantwortet

    Jerome,

    This is now:

    ActivateAudioInterfaceAsync

    Best Wishes - Eric

  • Dienstag, 12. Juni 2012 21:50
    Moderator
     
     Beantwortet

    Jerome & Community,

    The API has not been indexed by the MSDN index server. The documentation can be found here:

    ActivateAudioInterfaceAsync function

    http://msdn.microsoft.com/en-us/library/windows/desktop/jj128298(v=vs.85).aspx

    -James


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

  • Dienstag, 12. Juni 2012 22:23
    Moderator
     
     Beantwortet

    For Jerome & Community.  Pay special attention to the remarks section for ActivateAudioInterfaceAsync it should save you a lot of time.