2011-10-09 3 views
2

이 코드 조각은 시뮬레이터에서 정상적으로 작동합니다. 그러나 내 iPad에서 내보내기를 실행하려고하면 진행률 값 0.14583-ish가 항상 중단됩니다. 왜 누군가가 나를 알아낼 수 있습니까? 꽤 잠시 동안 이것에 붙어 있었다.AVAssetExportSession 진행률이 ipad에서는 멈추지 만 시뮬레이터에서는 멈추지 않습니다

NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:composition]; 
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality]) { 
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] 
              initWithAsset:composition presetName:AVAssetExportPresetLowQuality]; 


    exportSession.outputURL = [NSURL fileURLWithPath:[[ShowDAO getUserDocumentDir] stringByAppendingString:exportFilename]]; 
    exportSession.outputFileType = AVFileTypeQuickTimeMovie; 

    CMTime start = CMTimeMakeWithSeconds(0, 1); 
    CMTime duration = CMTimeMakeWithSeconds(1000, 1); 
    CMTimeRange range = CMTimeRangeMake(start, duration); 
    exportSession.timeRange = range; 

    [exportSession exportAsynchronouslyWithCompletionHandler:^{ 
     switch ([exportSession status]) { 
      case AVAssetExportSessionStatusCompleted: 
       NSLog(@"Export Completed"); 
       break; 
      case AVAssetExportSessionStatusFailed: 
       NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]); 
       break; 
      case AVAssetExportSessionStatusCancelled: 
       NSLog(@"Export cancelled"); 
       break; 
      default: 
       break; 
     } 


    }]; 

    while(exportSession.progress != 1.0){ 
     NSLog(@"loading... : %f",exportSession.progress); 
     sleep(1); 
    } 
    [exportSession release]; 

} 

답변

3
while(exportSession.progress != 1.0){ 
    NSLog(@"loading... : %f",exportSession.progress); 
    sleep(1); 
} 

이 while 루프는 메인 스레드를 차단 :

여기 내 코드입니다. NSLog가 제대로 작동하지 않을 수도 있습니다. while 루프없이 사용해 보시겠습니까?

+1

그래서 그는 수면을 취하고 있습니다 (1). 나는 [NSThread sleepForTimeInterval : 1.0]을 선호한다. –

관련 문제