AVAudioSession currentRoute
@property(readonly) AVAudioSessionRouteDescription *currentRoute
Discussion of [AVAudioSession currentRoute]
The current audio route contains information about the input and output ports involved in the session. You can use the object in this property to retrieve those ports and get information about them.
AVAudioSession currentRoute example.
- (BOOL)isHeadsetPluggedIn
{
// Get array of current audio outputs (there should only be one)
NSArray *outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
NSString *portName = [[outputs objectAtIndex:0] portName];
if ([portName isEqualToString:@"Headphones"]) {
return YES;
}
return NO;
}
{
// Get array of current audio outputs (there should only be one)
NSArray *outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
NSString *portName = [[outputs objectAtIndex:0] portName];
if ([portName isEqualToString:@"Headphones"]) {
return YES;
}
return NO;
}
Example of [AVAudioSession currentRoute].
AVAudioSessionRouteDescription *route = [[AVAudioSession sharedInstance] currentRoute];
for(AVAudioSessionPortDescription *port in route.outputs) {
NSLog(@"AUDIO_OUTPUT IS NOW: %@",port.portType);
}
for(AVAudioSessionPortDescription *port in route.outputs) {
NSLog(@"AUDIO_OUTPUT IS NOW: %@",port.portType);
}