AudioSession.AudioRouteChanged Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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) => {
DisplayRoutes ("Current Routes", args.CurrentInputRoute, args.CurrentOutputRoutes),
DisplayRoutes ("Old Routes", args.PreviousInputRoute, args.PreviousOutputRoutes),
Console.WriteLine (args.Reason);
};
}