Share via


AVAudioSession.Notifications.ObserveRouteChange Metodo

Definizione

Overload

ObserveRouteChange(EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notifica fortemente tipizzata per la RouteChangeNotification costante.

ObserveRouteChange(NSObject, EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notifica fortemente tipizzata per la RouteChangeNotification costante.

ObserveRouteChange(EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notifica fortemente tipizzata per la RouteChangeNotification costante.

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

Parametri

handler
EventHandler<AVAudioSessionRouteChangeEventArgs>

Metodo da richiamare quando viene pubblicata la notifica.

Restituisce

Oggetto token che può essere usato per arrestare la ricezione delle notifiche eliminandolo o passandolo a RemoveObservers(IEnumerable<NSObject>)

Commenti

Nell'esempio seguente viene illustrato come gli sviluppatori possono usare questo metodo nel codice:

//
// Lambda style
//

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

    Console.WriteLine ("Reason", args.Reason);
    Console.WriteLine ("PreviousRoute", args.PreviousRoute);
});

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

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

    Console.WriteLine ("Reason", args.Reason);
    Console.WriteLine ("PreviousRoute", args.PreviousRoute);
}

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

void Teardown ()
{
    notification.Dispose ();
}

Si applica a

ObserveRouteChange(NSObject, EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notifica fortemente tipizzata per la RouteChangeNotification costante.

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

Parametri

objectToObserve
NSObject

Oggetto specifico da osservare.

handler
EventHandler<AVAudioSessionRouteChangeEventArgs>

Gestore che risponde alla notifica quando si verifica.

Restituisce

Oggetto token che può essere usato per arrestare la ricezione delle notifiche eliminandolo o passandolo a RemoveObservers(IEnumerable<NSObject>)

Commenti

Questo metodo può essere usato per sottoscrivere RouteChangeNotification le notifiche.

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

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

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

Si applica a