Table of Contents

Class MMDeviceNotificationClient

Namespace
NAudio.CoreAudioApi
Assembly
NAudio.Wasapi.dll

High-level, event-based subscription to Windows Core Audio endpoint notifications. Obtain one from CreateNotificationClient(bool), subscribe to the events you care about, and Dispose() it (or the owning enumerator) when done.

public sealed class MMDeviceNotificationClient : IDisposable
Inheritance
MMDeviceNotificationClient
Implements
Inherited Members

Remarks

This is the recommended way to react to device add/remove, state changes, default-device changes, and property-value changes. It wraps the raw Core Audio COM callback interface internally, so callers never need to implement a [GeneratedComClass], enable unsafe code, or manage the CCW lifetime themselves.

By default the events are marshalled to the SynchronizationContext captured when the client was created (e.g. the UI thread of a WinForms/WPF app), so handlers can touch UI state directly. Pass useSynchronizationContext: false to receive events synchronously on the Windows audio worker thread instead — in which case handlers must be nonblocking and must not call back into the audio stack (e.g. disposing a player/recorder), which risks a deadlock.

Methods

Dispose()

Unregisters from endpoint notifications. Safe to call multiple times. Disposing the owning MMDeviceEnumerator also releases the registration.

public void Dispose()

Events

DefaultDeviceChanged

Raised when the default endpoint device for a given data-flow direction and role changes.

public event EventHandler<DefaultDeviceChangedEventArgs> DefaultDeviceChanged

Event Type

EventHandler<DefaultDeviceChangedEventArgs>

DeviceAdded

Raised when a new endpoint device is added.

public event EventHandler<DeviceNotificationEventArgs> DeviceAdded

Event Type

EventHandler<DeviceNotificationEventArgs>

DeviceRemoved

Raised when an endpoint device is removed.

public event EventHandler<DeviceNotificationEventArgs> DeviceRemoved

Event Type

EventHandler<DeviceNotificationEventArgs>

DeviceStateChanged

Raised when the state of an endpoint device changes (active, disabled, not-present, unplugged).

public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged

Event Type

EventHandler<DeviceStateChangedEventArgs>

PropertyValueChanged

Raised when a property value of an endpoint device changes. This can be high-frequency (for example a volume change fires it), so keep handlers cheap.

public event EventHandler<DevicePropertyChangedEventArgs> PropertyValueChanged

Event Type

EventHandler<DevicePropertyChangedEventArgs>