Share via


AVAudioSession.Notifications.ObserveInterruption Method

Definition

Overloads

ObserveInterruption(EventHandler<AVAudioSessionInterruptionEventArgs>)

Strongly typed notification for the InterruptionNotification constant.

public static Foundation.NSObject ObserveInterruption(EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> handler);
static member ObserveInterruption : EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> -> Foundation.NSObject

Parameters

handler
EventHandler<AVAudioSessionInterruptionEventArgs>

The handler that responds to the notification when it occurs.

Returns

Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>).

Remarks

This method can be used to subscribe to InterruptionNotification notifications.

// Listen to all notifications posted for any object
var token = AVAudioSession.Notifications.ObserveInterruption ((notification) => {
  Console.WriteLine ("Observed InterruptionNotification!");
};

// Stop listening for notifications
token.Dispose ();

Applies to

ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>)

Strongly typed notification for the InterruptionNotification constant.

public static Foundation.NSObject ObserveInterruption(Foundation.NSObject objectToObserve, EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> handler);
static member ObserveInterruption : Foundation.NSObject * EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> -> Foundation.NSObject

Parameters

objectToObserve
NSObject

The specific object to observe.

handler
EventHandler<AVAudioSessionInterruptionEventArgs>

The handler that responds to the notification when it occurs.

Returns

Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>).

Remarks

This method can be used to subscribe to InterruptionNotification notifications.

// Listen to all notifications posted for a single object
var token = AVAudioSession.Notifications.ObserveInterruption (objectToObserve, (notification) => {
  Console.WriteLine ($"Observed InterruptionNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Applies to