Partilhar via


AVAudioSession.Notifications.ObserveRouteChange Método

Definição

Sobrecargas

ObserveRouteChange(EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificação fortemente tipada para a RouteChangeNotification constante.

ObserveRouteChange(NSObject, EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificação fortemente tipada para a RouteChangeNotification constante.

ObserveRouteChange(EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificação fortemente tipada para a 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 a ser invocado quando a notificação é postada.

Retornos

Objeto de token que pode ser usado para parar de receber notificações descartando-o ou passando-o para RemoveObservers(IEnumerable<NSObject>)

Comentários

O exemplo a seguir mostra como os desenvolvedores podem usar esse método em seu 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 ();
}

Aplica-se a

ObserveRouteChange(NSObject, EventHandler<AVAudioSessionRouteChangeEventArgs>)

Notificação fortemente tipada para a 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

O objeto específico a ser observado.

handler
EventHandler<AVAudioSessionRouteChangeEventArgs>

O manipulador que responde à notificação quando ela ocorre.

Retornos

Objeto de token que pode ser usado para parar de receber notificações descartando-o ou passando-o para RemoveObservers(IEnumerable<NSObject>)

Comentários

Esse método pode ser usado para assinar RouteChangeNotification notificações.

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

Aplica-se a