AVAssetExportSession进度卡在ipad上但不在模拟器上

时间:2011-10-09 10:49:57

标签: ios avfoundation avassetexportsession

这段代码在模拟器上运行良好。但是,当我尝试在iPad上运行导出时,它总是挂起进度值0.14583-ish。有人可以帮我找出原因吗?已经坚持了很长一段时间。

这是我的代码:

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];

}

1 个答案:

答案 0 :(得分:3)

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

这个while循环阻塞了主线程。 NSLog可能无法正常启动。没有while循环尝试吗?