2012-09-29 2 views
0

AVRecorder와 AVPlayer를 많이 사용하고 있습니다. 나는 둘 다, 내 애플에 돌아 왔을 때, 그녀가 백그라운드에있을 때까지 기다렸다가, 예를 들어 내가 기록하려고한다면, 시작하기까지 4 초가 걸린다.배경 모드에서 돌아올 때 AVRecorder가 지연됩니까?

내 코드에서 녹음하기 전에 전에 을 녹음 할 준비가되어 있습니다.하지만 앱으로 돌아 가면 도움이되지 않습니다.

개선하기 위해 무엇을 할 수 있습니까?

이는 (배경에서하지 않을 경우 다시, 시작에!) 응용 프로그램이 열려있을 때 이루어집니다

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


} 

감사합니다!

답변

0

다른 앱이 활성 AVAudioSession을 시작하여 마이크 컨트롤을 가져온 경우 iOS가 해당 앱의 컨트롤을 페이드 아웃하고 세션을 활성화 할 때 제공합니다. 이 작업은 1-2 초 정도 걸릴 수 있습니다. 무슨 일이 일어나고있는거야? 또는 당신을 천천히 다른 뭔가입니까?

관련 문제