AVAssetExportSession progress gets stuck on ipad but not on simulator
This piece of code works fine on the simulator. However, when I try to run the export on my iPad, it always hangs at progress value 0.14583-ish. Can somebody help me figure out why? been stuck on this for quite awhile.
Here is my code:
NSArray *compatibleP开发者_如何转开发resets = [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];
}
while(exportSession.progress != 1.0){
NSLog(@"loading... : %f",exportSession.progress);
sleep(1);
}
This while loop is blocking the main thread. The NSLog might not be able to fire properly. Try it without the while loop?
精彩评论