Edit

Share via


AudioSession.AudioRouteChanged Event

Definition

Event raised when the input and output audio routes change on the device.

public static event EventHandler<AudioToolbox.AudioSessionRouteChangeEventArgs> AudioRouteChanged;
member this.AudioRouteChanged : EventHandler<AudioToolbox.AudioSessionRouteChangeEventArgs> 

Event Type

Remarks

This event is raised when audio hardware is plugged or unplugged from your device. The event receives a AudioSessionRouteChangeEventArgs instance that contains information about the reason for the change and both the old input sources and output targets as well as the new ones.

void DisplayRoutes (string caption, AudioSessionInputRouteKind input, AudioSessionOutputRouteKind [] output)
{
	if (output == null)
		Console.WriteLine ("No outputs");
	else if (output.Length == 1)	
		Console.WriteLine ("Output {0}", output [0]);
	else
		for (int i = 0; i < output.Lenght; i++)
			Console.WriteLine ("Output {0}", output [i])

	Console.WriteLine (input.ToString ());
} 

void Setup ()
{
    AudioSession.AudioRouteChanged += (sender, args) =&gt; {
        DisplayRoutes ("Current Routes", args.CurrentInputRoute, args.CurrentOutputRoutes),
        DisplayRoutes ("Old Routes", args.PreviousInputRoute, args.PreviousOutputRoutes),
        Console.WriteLine (args.Reason);
    };
}

Applies to