AVAudioSession.Notifications.ObserveRouteChange Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
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
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.
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 ();