AVRecorder と AVPlayer をよく使用しています。彼女がバックグラウンドになった後、アプリに戻ったときに両方が遅延するのを見ました。たとえば、録音しようとすると、開始するまでに4秒かかります。
私のコードでは、録音する前に録音する準備をしていますが、アプリに戻っても役に立ちません。
それを改善するために私は何ができますか?
これは、アプリが開いているときに行われます(バックグラウンドから戻ったときではなく、開始時です!)
-(void)prepareToRecord
{
NSArray *dirPaths;
NSString *docsDir;
NSString *sound=[NSString stringWithFormat:@"sound%d.caf",[memoryInstnace getNextFreePlace]];
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
docsDir = [dirPaths objectAtIndex:0];
currentSoundFilePath = [docsDir stringByAppendingPathComponent:sound];
NSURL *soundFileURL = [NSURL fileURLWithPath:currentSoundFilePath];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:settings error:&error];
//to not having a delay befor record
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
if (recorder)
{
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
}
else
NSLog( @"error in recordings" );
}
ありがとう !