0

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"  );


}

ありがとう !

4

1 に答える 1

0

別のアプリがアクティブなAVAudioSessionを開始してマイクの制御を取得した場合、iOSはそのアプリから制御をフェードアウトし、セッションをアクティブ化したときにそれを提供します。これには1〜2秒かかる場合があります。これは何が起こっているのですか?または何か他のものがあなたを遅くしていますか?

于 2012-10-02T21:46:23.737 に答える