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];
}
這就是爲什麼他睡覺(1)。我更喜歡[NSThread sleepForTimeInterval:1.0]; –