이런 식으로 뭔가를 시도, 그 이상이 필요하지만 당신은 그것을 아래로 깎아 내다보다 :
+ (NSString *) demonstrateInputSelection
{
NSError* theError = nil;
BOOL result = YES;
NSMutableString *info = [[NSMutableString alloc] init];
[info appendString: @" Device Audio Input Hardware\n"];
NSString *str = nil;
if(iOSMajorVersion < 7){
str = @"No input device information available";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
return info;
}
AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];
result = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&theError];
if (!result)
{
NSLog(@"setCategory failed");
}
result = [myAudioSession setActive:YES error:&theError];
if (!result)
{
NSLog(@"setActive failed");
}
// Get the set of available inputs. If there are no audio accessories attached, there will be
// only one available input -- the built in microphone.
NSArray* inputs = [myAudioSession availableInputs];
str = [NSString stringWithFormat:@"\n--- Ports available on %@: %d ---", [UIDevice currentDevice].name , [inputs count]];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
// Locate the Port corresponding to the built-in microphone.
AVAudioSessionPortDescription* builtInMicPort = nil;
AVAudioSessionDataSourceDescription* frontDataSource = nil;
for (AVAudioSessionPortDescription* port in inputs)
{
// Print out a description of the data sources for the built-in microphone
str = @"\n**********";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
str = [NSString stringWithFormat:@"Port :\"%@\": UID:%@", port.portName, port.UID ];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
if([port.dataSources count]){
str = [NSString stringWithFormat:@"Port has %d data sources",(unsigned)[port.dataSources count] ];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
str = [NSString stringWithFormat:@">%@", port.dataSources];
NSLog(@"%@",str);
// [info appendFormat:@"%@\n",str];
if([port.portType isEqualToString:AVAudioSessionPortLineIn]){
str = @"Line Input found";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
else if([port.portType isEqualToString:AVAudioSessionPortUSBAudio]){
str = @"USB Audio found";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
else if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]){
builtInMicPort = port;
str = @"Built-in Mic found";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
else if ([port.portType isEqualToString:AVAudioSessionPortHeadsetMic]){
builtInMicPort = port;
str = @"Headset Mic found";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
else{
str = @"Other input source found";
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
// loop over the built-in mic's data sources and attempt to locate the front microphone
for (AVAudioSessionDataSourceDescription* source in port.dataSources)
{
str = [NSString stringWithFormat:@"\nName:%@ (%d) \nPolar:%@ \nType:%@ \nPatterns:%@", source.dataSourceName, [source.dataSourceID intValue], source.selectedPolarPattern, port.portType, source.supportedPolarPatterns];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
// if ([source.orientation isEqual:AVAudioSessionOrientationFront])
// {
// frontDataSource = source;
// break;
// }
} // end data source iteration
}
str = @"\n---- Current Selected Ports ----\n";
NSLog(@"%@",str);
[info appendFormat:@"%@",str];
NSArray *currentInputs = myAudioSession.currentRoute.inputs;
// str = [NSString stringWithFormat:@"\n%d current input ports", [currentInputs count]];
// NSLog(@"%@",str);
// [info appendFormat:@"%@\n",str];
for(AVAudioSessionPortDescription *port in currentInputs){
str = [NSString stringWithFormat:@"\nInput Port :\"%@\":", port.portName ];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
if([port.dataSources count]){
str = [NSString stringWithFormat:@"Port has %d data sources",(unsigned)[port.dataSources count] ];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
str = [NSString stringWithFormat:@"Selected data source:%@", port.selectedDataSource.dataSourceName];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
if([port.selectedDataSource.supportedPolarPatterns count] > 0){
str = [NSString stringWithFormat:@"Selected polar pattern:%@", port.selectedDataSource.selectedPolarPattern];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
}
}
NSArray *currentOutputs = myAudioSession.currentRoute.outputs;
// str = [NSString stringWithFormat:@"\n%d current output ports", [currentOutputs count]];
// NSLog(@"%@",str);
// [info appendFormat:@"%@\n",str];
for(AVAudioSessionPortDescription *port in currentOutputs){
str = [NSString stringWithFormat:@"\nOutput Port :\"%@\":", port.portName ];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
if([port.dataSources count]){
str = [NSString stringWithFormat:@"Port has %d data sources",(unsigned)[port.dataSources count] ];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
str = [NSString stringWithFormat:@"Selected data source:%@", port.selectedDataSource.dataSourceName];
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
}
}
// str = [NSString stringWithFormat:@"\Current Route: %@ Source:%@\n", myAudioSession.currentRoute.portName, myAudioSession.preferredInput.selectedDataSource.dataSourceName];
// NSLog(@"%@",str);
// [info appendFormat:@"%@\n",str];
if(myAudioSession.preferredInput.portName){
str = [NSString stringWithFormat:@"\nPreferred Port: %@ Source:%@\n", myAudioSession.preferredInput.portName, myAudioSession.preferredInput.selectedDataSource.dataSourceName];
} else {
str = @"\nNo Preferred Port set";
}
NSLog(@"%@",str);
[info appendFormat:@"%@\n",str];
return info;
if (frontDataSource)
{
NSLog(@"Currently selected source is \"%@\" for port \"%@\"", builtInMicPort.selectedDataSource.dataSourceName, builtInMicPort.portName);
NSLog(@"Attempting to select source \"%@\" on port \"%@\"", frontDataSource, builtInMicPort.portName);
// Set a preference for the front data source.
theError = nil;
result = [builtInMicPort setPreferredDataSource:frontDataSource error:&theError];
if (!result)
{
// an error occurred. Handle it!
NSLog(@"setPreferredDataSource failed");
}
}
// Make sure the built-in mic is selected for input. This will be a no-op if the built-in mic is
// already the current input Port.
theError = nil;
result = [myAudioSession setPreferredInput:builtInMicPort error:&theError];
if (!result)
{
// an error occurred. Handle it!
NSLog(@"setPreferredInput failed");
}
return info;
}
다소 도움이되지만, 이것은 _available_ 출력을 표시하는 방법에 대한 질문에 대답하지 않는 접근으로 더 많은 자유를 줄 것이다 MultipleRoute 범주를 사용하는 것입니다 . 현재 사용할 수있는 출력물 목록을 보여주는 유일한 방법은 제공된 'MPVolumeView'의 경로 버튼을 사용하는 것입니다. – Stuart
입력 소스를 선택한 후 출력 소스를 선택할 수 있습니까? 나는 이것을 할 수없는 것처럼 보입니다. –