locked
[UWP]AudioGraph: How to select an input device RRS feed

  • Question

  • Seems obvious but I can't find an example.

    My guess was that you create a graph using CreateAsync() (But what's in the settings?) then call CreateDeviceInputNodeAsync() to specify the input device.

    If you want to capture audio from the default device then you just call this: CreateDeviceInputNodeAsync(MediaCategory.Other) - but what do you do if you want to select another device? Is it possible to select a render device as an input node?


    • Edited by Barry Wang Wednesday, April 5, 2017 5:28 AM title tag
    Tuesday, April 4, 2017 6:12 AM

Answers

  • Hello Shaul_ei,

    Per our doc you can see the following:

    If you want to specify a specific audio capture device for the device input node, you can use the Windows.Devices.Enumeration.DeviceInformation class to get a list of the system's available audio capture devices by calling FindAllAsync and passing in the audio render device selector returned by Windows.Media.Devices.MediaDevice.GetAudioRenderSelector. You can choose one of the returned DeviceInformation objects programmatically or show UI to allow the user to select a device and then pass it into CreateDeviceInputNodeAsync.

    The code is already here:

    Windows.Devices.Enumeration.DeviceInformationCollection devices =
     await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Media.Devices.MediaDevice.GetAudioCaptureSelector());
    
    // Show UI to allow the user to select a device
    Windows.Devices.Enumeration.DeviceInformation selectedDevice = ShowMyDeviceSelectionUI(devices);
    
    CreateAudioDeviceInputNodeResult result =
        await audioGraph.CreateDeviceInputNodeAsync(Windows.Media.Capture.MediaCategory.Media, audioGraph.EncodingProperties, selectedDevice);

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Barry Wang Wednesday, April 5, 2017 5:32 AM
    • Marked as answer by shaul_ei Wednesday, April 5, 2017 8:48 AM
    Wednesday, April 5, 2017 5:32 AM

All replies

  • Hello Shaul_ei,

    Per our doc you can see the following:

    If you want to specify a specific audio capture device for the device input node, you can use the Windows.Devices.Enumeration.DeviceInformation class to get a list of the system's available audio capture devices by calling FindAllAsync and passing in the audio render device selector returned by Windows.Media.Devices.MediaDevice.GetAudioRenderSelector. You can choose one of the returned DeviceInformation objects programmatically or show UI to allow the user to select a device and then pass it into CreateDeviceInputNodeAsync.

    The code is already here:

    Windows.Devices.Enumeration.DeviceInformationCollection devices =
     await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Media.Devices.MediaDevice.GetAudioCaptureSelector());
    
    // Show UI to allow the user to select a device
    Windows.Devices.Enumeration.DeviceInformation selectedDevice = ShowMyDeviceSelectionUI(devices);
    
    CreateAudioDeviceInputNodeResult result =
        await audioGraph.CreateDeviceInputNodeAsync(Windows.Media.Capture.MediaCategory.Media, audioGraph.EncodingProperties, selectedDevice);

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Barry Wang Wednesday, April 5, 2017 5:32 AM
    • Marked as answer by shaul_ei Wednesday, April 5, 2017 8:48 AM
    Wednesday, April 5, 2017 5:32 AM
  • Hi Barry,

    Is there a way to programatically select a specific device from the list returned from the FindAllAsync message? What I want to do is programatically choose the headset/headphone if it is available and otherwise the speaker (for playback), and the headset if it is available and other wise the microphone (for record).

    Is there a way to identify a category of device (speaker, headset, headphone, microphone) by an identifier or other attribute?

    Do you have any idea how to do that?

    Thanks,

    Bridget Slocum



    • Edited by B Slocum Tuesday, April 11, 2017 3:05 PM
    Tuesday, April 11, 2017 2:58 PM