2011-04-25 2 views
2

내 응용 프로그램은 오디오를 읽고 제작자/소비자 설정에서 다시 재생합니다. 소비자 스레드는 하드웨어에 렌더링 할 새 샘플을 요청합니다. 제작자 스레드는 AVAssetReader를 사용하여 디스크에서 오디오 데이터를 버퍼로 읽습니다. 생산자 스레드는 루프에서 실행되어 더 많은 샘플을 읽어야하는지 확인합니다. 제작자의 버퍼 크기는 오디오의 4 초와 같습니다.AVAssetReader가 오디오를 읽은 다음 실패합니다.

오디오를 버퍼링하도록 앱을 지시하면 오류없이 샘플을 성공적으로 읽습니다. 제작자 스레드를 트리거하여 오디오 렌더링을 시작하면 4 초 버퍼가 완벽하게 재생 된 다음 침묵합니다.

CMSampleBufferRef ref = [readaudiofile copyNextSampleBuffer]; 
if (ref == NULL && filereader.status == AVAssetReaderStatusFailed) { 
    NSLog(@"reader failed: %@", filereader.error); 
} 
// this produces: 
// {NSLocalizedFailureReason=An unknown error occurred (-12785), 
// NSUnderlyingError=0x161f60 "The operation couldn’t be completed. 
// (OSStatus error -12785.)", NSLocalizedDescription=The operation 
// could not be completed} 

내 생산자 스레드 코드는 기능 코드 예제 MusicLibraryRemoteIODemo 동일합니다 : 추가 조사는 내 자산 리더, 재생의 시작에 초기 버퍼링 한 후 읽기 때문에 더 이상의 샘플을 실패하지 않습니다 것을 알 수있다. 내 소비자 스레드 코드가 다르긴하지만 나는 며칠 동안 두 줄을 한 줄씩 비교해 보았고 장애를 찾을 수없는 것처럼 보였다. AVAssetReader 판독기가 실패하게 된 원인은 무엇입니까?

This post은 유사한 솔루션을 설명하며 오디오 세션을 올바르게 설정해야한다고 결론지었습니다 (방법은 밝히지 않았지만). AVAudioSesion 구성과 AVAssetReader의 동작 사이에 어떤 연결이 있습니까?

나는이 같은 오류가 발생했다

답변

3

는, 나뿐만 아니라 다른 스레드에서이 작동

- (void)setupAudio { 
    [[AVAudioSession sharedInstance] setDelegate:self]; 
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; 
    NSError *activationError = nil; 
    [[AVAudioSession sharedInstance] setActive: YES error:&activationError]; 

    NSLog(@"setupAudio ACTIVATION ERROR IS %@", activationError); 
    [[AVAudioSession sharedInstance] setPreferredIOBufferDuration:0.1 error:&activationError]; 
    NSLog(@"setupAudio BUFFER DURATION ERROR IS %@", activationError); 
} 
+0

을이 대답을 기록했다. 로킨. – ManicBlowfish

관련 문제