Share via


AudioStateMonitor Class

Definition

Allows a UWP app to determine if any of the app's audio streams are currently being muted or having their volume reduced by the system.

public ref class AudioStateMonitor sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 393216)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class AudioStateMonitor final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 393216)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class AudioStateMonitor
Public NotInheritable Class AudioStateMonitor
Inheritance
Object Platform::Object IInspectable AudioStateMonitor
Attributes

Windows requirements

Device family
Windows 10, version 1803 (introduced in 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v6.0)

Remarks

Windows dynamically mutes or lowers the level of audio streams in response to system events. For example, the volume of a podcast app's audio render stream may be lowered while an alarm is ringing. Or an audio recording app may have their capture stream muted when the app moves to the background. This class allows apps to respond to changes in the level of their audio streams. For example, a podcast app may choose to pause playback when the sound level is lowered by the system and then resume playback when the volume level returns to normal. Or, an audio recording app may choose to stop recording while its capture stream is muted.

Create an AudioStateMonitor by calling one of its factory methods that determines which streams are monitored based on their MediaCategory, AudioDeviceRole, the ID of the associated audio device, and whether the stream is capturing or rendering audio.

Use the SoundLevel property to determine the current sound level of the monitored streams. You can check the value of this property, to determine if a category of audio streams will be muted or have its volume lowered, before initiating audio capture or playback. You can register a handler for the SoundLevelChanged event to receive notifications when the sound level for a category of audio streams changes, and then check the SoundLevel property to determine the new current audio level.

For more information on using AudioStateMonitor in a UWP app, see Detect and respond to audio state changes.

Properties

SoundLevel

Gets a value indicating the current sound level of the audio streams being monitored by the AudioStateMonitor.

Methods

CreateForCaptureMonitoring()

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for all audio capture streams.

CreateForCaptureMonitoring(MediaCategory, AudioDeviceRole)

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for audio capture streams with the specified MediaCategory and AudioDeviceRole.

CreateForCaptureMonitoring(MediaCategory)

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for audio capture streams with the specified MediaCategory.

CreateForCaptureMonitoringWithCategoryAndDeviceId(MediaCategory, String)

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for audio capture streams with the specified MediaCategory that are using the specified audio device.

CreateForRenderMonitoring()

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for all audio render streams.

CreateForRenderMonitoring(AudioRenderCategory, AudioDeviceRole)

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for render streams with the specified MediaCategory and AudioDeviceRole.

CreateForRenderMonitoring(AudioRenderCategory)

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for audio render streams with the specified MediaCategory.

CreateForRenderMonitoringWithCategoryAndDeviceId(AudioRenderCategory, String)

Initializes a new instance of the AudioStateMonitor class that monitors the sound level for audio render streams with the specified MediaCategory that are using the specified audio device.

Events

SoundLevelChanged

Occurs when the system changes the sound level of the audio streams being monitored by the AudioStateMonitor.

Applies to