filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.15k stars 451 forks source link

"Unknown HRESULT" when try to get PropertyStore items #433

Closed steam3d closed 3 years ago

steam3d commented 3 years ago

This my code

using (var enumerator = new MMDeviceEnumerator())
{
    var audioEndpoints = enumerator.EnumAudioEndpoints(dataFlow, DeviceState.All);

    foreach (var audioEnd in audioEndpoints)
    {
        foreach (var property in audioEnd.PropertyStore)
        {
            Console.WriteLine(String.Format("{0} | {1} : {2} | {3}", property.Key, property.Key.GetType(), property.Value, property.Value.GetType()));
        }
    }
}

I got the error

CSCore.Win32.Win32ComException: 'IPropertyStore::GetValue caused an error: 0xe000020b, "Unknown HRESULT".'

I found that audioEndpoints have {CSCore.CoreAudioAPI.MMDevice} when you try to get FrendlyName you get this error.

image

barrien2 commented 3 years ago

Does changing DeviceState.All to DeviceState.Active fix it? I think there's an issue with disabled devices

steam3d commented 3 years ago

You are right, better way just skip device that rise error when using DeviceState.All