我試圖克服這一段時間。我試圖錄制聲音,但AVAudioRecorder在屏幕鎖定時不錄製。一旦屏幕解鎖,它會繼續錄製,但屏幕鎖定時錄製的音頻永遠丟失。我無法找到我在做什麼錯:AVAudioRecorder不記錄屏幕鎖定
-(void) startRecording
{
// Begin the recording session.
_session = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
NSError *startRecordError;
[_session setActive:YES error:&startRecordError];
[self GKLog:[NSString stringWithFormat:@"recorder session error? :%@", startRecordError]];
[_session setCategory: AVAudioSessionCategoryRecord error: &setCategoryError];
if (setCategoryError) { NSLog(@"some error");}
//set me as delegate
_session.delegate=(id <AVAudioSessionDelegate>) self;
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue :[NSNumber numberWithInt:8] forKey:AVEncoderBitRateKey];
[recordSetting setValue:[NSNumber numberWithFloat:8000.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
if (!self.currentPath)
{
NSLog(@"can't record, no path set!");
return;
}
NSError *error;
NSURL *url=[NSURL fileURLWithPath:self.currentPath];
//Setup the recorder to use this file and record to it.
_recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&error];
[self GKLog:[NSString stringWithFormat:@" recorder:%@",_recorder]];
_recorder.delegate=(id <AVAudioRecorderDelegate>) self;
[_recorder prepareToRecord];
//Start the actual Recording
[_recorder record];
}
有什麼想法嗎?
,以後會嘗試: 「你大概需要設置 UIBackgroundModes 音頻 的信息。 plist「 –
user1258240
2012-03-29 22:02:10
好吧 - 剛剛嘗試我以前的評論,它的工作!太糟糕了,我無法在AVAudioRecorder或AVAudioSession開發人員文檔中找到它。這裏有一個鏈接,我找到它的位置:[http://stackoverflow.com/questions/3848172/ios-multitasking-for-an-audio-recording-application] – user1258240 2012-03-29 22:30:56
我希望我能標記自己是這個問題的回答者:) – user1258240 2012-03-29 22:32:06