Edit

Share via


AVAudioSession.Notifications.ObserveInterruption Method

Definition

Overloads

ObserveInterruption(EventHandler<AVAudioSessionInterruptionEventArgs>)

Strongly typed notification for the InterruptionNotification constant.

ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>)

Strongly typed notification for the InterruptionNotification constant.

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>

Method to invoke when the notification is posted.

Returns

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

Remarks

The following example shows how developers can use this method in their code:

//
// Lambda style
//

// listening
notification = AVAudioSession.Notifications.ObserveInterruption ((sender, args) => {
    /* Access strongly typed args */
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("InterruptionType", args.InterruptionType);
    Console.WriteLine ("Option", args.Option);
    Console.WriteLine ("WasSuspended", args.WasSuspended);
});

// To stop listening:
notification.Dispose ();

//
//Method style
//
NSObject notification;
void Callback (object sender, AVFoundation.AVAudioSessionInterruptionEventArgs args)
{
    // Access strongly typed args
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("InterruptionType", args.InterruptionType);
    Console.WriteLine ("Option", args.Option);
    Console.WriteLine ("WasSuspended", args.WasSuspended);
}

void Setup ()
{
    notification = AVAudioSession.Notifications.ObserveInterruption (Callback);
}

void Teardown ()
{
    notification.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 for InterruptionNotification notifications.

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

// 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