Search code examples
c#wpfscreen-captureaudio-device

Get Speakers out of AudioDevices


I'm trying to do a ScreenCapture using Microsoft Expression Encoder. I want to get the Speakers out of AudioDevices (NOT the Microphone). My Problem is, that every Device has another name for it's speakers.

I came up with the solution to check, if the device's name contains "Speaker", but i think this won't work on every clients device.

private EncoderDevice GetAudioDevice()
{
    EncoderDevice audioDevice = null;
    Collection<EncoderDevice> audioDevices = 
        EncoderDevices.FindDevices(EncoderDeviceType.Audio);

    try
    {
        foreach (var item in audioDevices)
        {
            if (item.Name.ToUpper().Contains("SPEAKER"))
            {
                audioDevice = item;
            }
            else
            {
                audioDevice = audioDevices.First();
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Keine AudioDevices gefunden!");
    }

    return audioDevice;
}

Anybody knows how to do that?


Solution

  • EncoderDevice has a Category enum property. Test with

    if (item.Category == EncoderDeviceCategory.Playback)
    {
        ...
    }
    

    A microphone would have a Category of EncoderDeviceCategory.Capture.

    See: