素晴らしいNAudioフレームワークを使用して、オーディオ デバイスのリストを取得しています。
しかし、私が見ているように、どのオーディオ デバイスが PC の統合オーディオであり、どのオーディオ デバイスがヘッドフォンであるかの違いはあり得ません。つまり、それらは同じ名前を持ち、ヘッドフォンを接続した場合にのみActive
状態になります。
ヘッドフォンを接続した状態でアプリケーションを起動した場合、現在のデバイスがヘッドフォンであり、PC の内蔵オーディオではないかどうかをどのように知ることができるでしょうか?
つまり、接続されたオーディオ デバイスが外部オーディオ デバイスであり、ヘッドフォン自体であることを NAduio 経由で検出できますか?
var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
// Allows you to enumerate rendering devices in certain states
var endpoints = enumerator.EnumerateAudioEndPoints(
DataFlow.Render,
DeviceState.Unplugged | DeviceState.Active);
foreach (var endpoint in endpoints)
{
Console.WriteLine("{0} - {1}", endpoint.DeviceFriendlyName, endpoint.State);
}
// Aswell as hook to the actual event
enumerator.RegisterEndpointNotificationCallback(new NotificationClient());
NotificationClient は次のように実装されます。
class NotificationClient : NAudio.CoreAudioApi.Interfaces.IMMNotificationClient
{
void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState newState)
{
Console.WriteLine("OnDeviceStateChanged\n Device Id -->{0} : Device State {1}", deviceId, newState);
}
void IMMNotificationClient.OnDeviceAdded(string pwstrDeviceId) { }
void IMMNotificationClient.OnDeviceRemoved(string deviceId) { }
void IMMNotificationClient.OnDefaultDeviceChanged(DataFlow flow, Role role, string defaultDeviceId) { }
void IMMNotificationClient.OnPropertyValueChanged(string pwstrDeviceId, PropertyKey key) { }
}