2
以下是我的記錄按鈕方法的內容。它會創建所需的文件,但無論記錄多長時間,創建的文件總是4kb和0秒,我無法弄清楚它爲什麼無效。 averagePowerPerChannel也會返回-120,我假設它是因爲文件已損壞。AVAudioRecorder記錄空白文件
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error;
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"sound.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
self.shotRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];
self.shotRecorder.delegate = self;
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[self.shotRecorder prepareToRecord];
self.shotRecorder.meteringEnabled = YES;
[self.shotRecorder record];
shotTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
}
解決了我的問題!謝謝! – nexuzzz