Compartir a través de


AVAudioSession.Notifications.ObserveRouteChange Método

Definición

Sobrecargas

ObserveRouteChange(EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificación fuertemente tipada para la RouteChangeNotification constante.

ObserveRouteChange(NSObject, EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificación fuertemente tipada para la RouteChangeNotification constante.

ObserveRouteChange(EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificación fuertemente tipada para la RouteChangeNotification constante.

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

Parámetros

handler
EventHandler<AVAudioSessionRouteChangeEventArgs>

Método para invocar cuando se publica la notificación.

Devoluciones

Objeto de token que se puede usar para dejar de recibir notificaciones al eliminarlo o pasarlo a RemoveObservers(IEnumerable<NSObject>)

Comentarios

En el ejemplo siguiente se muestra cómo los desarrolladores pueden usar este método en su código:

//
// 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 ();
}

Se aplica a

ObserveRouteChange(NSObject, EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificación fuertemente tipada para la RouteChangeNotification constante.

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

Parámetros

objectToObserve
NSObject

Objeto específico que se va a observar.

handler
EventHandler<AVAudioSessionRouteChangeEventArgs>

Controlador que responde a la notificación cuando se produce.

Devoluciones

Objeto de token que se puede usar para dejar de recibir notificaciones al eliminarlo o pasarlo a RemoveObservers(IEnumerable<NSObject>)

Comentarios

Este método se puede usar para suscribirse RouteChangeNotification a las notificaciones.

// 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 ();

Se aplica a