我想做什么:
我应该研究哪些iPhone API或示例代码?谢谢!
答案 0 :(得分:0)
您需要的是AVFoundation。使用它:
以下代码段用于录制:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
[audioSession setActive:YES error:&err];
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
[settings setValue: [NSNumber numberWithInt:kAudioFormatMPEGLayer3] forKey:AVFormatIDKey];
[settings setValue: [NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[settings setValue: [NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[settings setValue: [NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
NSURL *url = [NSURL fileURLWithPath: filepath];
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:settings error:&err];
[settings release];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
另外,你需要实现 - (void)audioRecorderDidFinishRecording :( AVAudioRecorder *)录音机成功:( BOOL)标志释放录音机。