Get Speakers out of AudioDevices

186 Views Asked by At

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?

1

There are 1 best solutions below

3
On BEST ANSWER

EncoderDevice has a Category enum property. Test with

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

A microphone would have a Category of EncoderDeviceCategory.Capture.

See: