我用objective-c录制音频。我使用以下代码:
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.m4a"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:12],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:16000.0],
AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC],
AVFormatIDKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];
if (error){
Log(@"error: %@", [error localizedDescription]);
} else {
[audioRecorder prepareToRecord];
[audioRecorder record];
}
这个在Ipad上完美运行,但在iphone上不起作用。不是来自Xcode的代码没有错误。 iphone已经过测试和工作的麦克风和扬声器。 “请勿打扰”功能已关闭。声音打开了。我只是没有从扬声器发出任何声音,而且它似乎正在录制。
问题:为什么声音不起作用?