Class AudioSessionControl
- Namespace
- AudioDeviceLib.CoreAudioApi
- Assembly
- AudioDeviceLib.dll
Managed wrapper over the Core Audio IAudioSessionControl2 interface. Represents a single
audio session (typically one application) and exposes its state, metadata and volume controls.
public sealed class AudioSessionControl : IDisposable
- Inheritance
-
AudioSessionControl
- Implements
- Inherited Members
Properties
AudioMeterInformation
Gets the session meter, or null if unsupported.
public AudioMeterInformation? AudioMeterInformation { get; }
Property Value
SimpleAudioVolume
Gets the session volume control, or null if unsupported.
public SimpleAudioVolume? SimpleAudioVolume { get; }
Property Value
State
Gets the current activity state of the session (inactive, active or expired).
public AudioSessionState State { get; }
Property Value
Exceptions
- COMException
Thrown when the underlying Core Audio call fails.
Methods
Dispose()
Unregisters any remaining session-event callbacks registered on this session.
public void Dispose()
RegisterAudioSessionNotification(IAudioSessionEvents)
Registers a callback to receive session change notifications.
public IDisposable RegisterAudioSessionNotification(IAudioSessionEvents eventConsumer)
Parameters
eventConsumerIAudioSessionEventsThe consumer that will receive IAudioSessionEvents callbacks.
Returns
- IDisposable
A token that unregisters the callback when disposed. Disposing the token is the foolproof way to stop notifications; you can also call UnregisterAudioSessionNotification(IAudioSessionEvents) with the same consumer instance.
Remarks
THREADING: the consumer's callbacks are raised by Windows Core Audio on arbitrary, non-UI threads and may arrive concurrently, so the implementation must be fast and thread-safe. Registering the same consumer again returns the same token for the existing registration without registering twice.
Exceptions
- ArgumentNullException
Thrown when
eventConsumeris null.- ObjectDisposedException
Thrown when this session has been disposed.
- COMException
Thrown when the underlying Core Audio call fails.
UnregisterAudioSessionNotification(IAudioSessionEvents)
Unregisters a previously registered session change callback.
public void UnregisterAudioSessionNotification(IAudioSessionEvents eventConsumer)
Parameters
eventConsumerIAudioSessionEventsThe same consumer instance that was passed to RegisterAudioSessionNotification(IAudioSessionEvents).
Remarks
Has no effect if the instance was not previously registered on this session.
Exceptions
- ArgumentNullException
Thrown when
eventConsumeris null.- COMException
Thrown when the underlying Core Audio call fails.