Reputation: 377
AVAssetExportSession never tells me when export has finished, but it does quickly and the file appears where supposed to be... I'm using exportAsynchronouslyWithCompletionHandler but it never enters the completion handler, any idea of why?
Im using an iPad 2 with iOS 8.3, dont have any other type to test and im using a recorded video stored in a local directory
- (IBAction)importButtonPressed:(UIButton *)sender {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[[PHImageManager defaultManager]requestAVAssetForVideo:self.selectedAsset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
if ([compatiblePresets containsObject:AVAssetExportPreset960x540]) {
exportSession = [[AVAssetExportSession alloc]
initWithAsset:asset presetName:AVAssetExportPreset960x540];
NSString *videoPath;
//Totally valid path to drop the video in
videoPath = [[FileManager sharedFileManager] pathToSaveNewVideo];
NSURL *outputhURL = [NSURL fileURLWithPath:videoPath];
exportSession.outputURL = outputhURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime adur = self.mPlayerItem.duration;
CMTime start = CMTimeMake(adur.value * self.lineCutter.startAt, adur.timescale);
CMTime duration = CMTimeMake(adur.value * (self.lineCutter.endsAt - self.lineCutter.startAt), adur.timescale);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
outputhURLBuff = outputhURL;
[self performSelectorOnMainThread:@selector(exportWithSession:) withObject:exportSession waitUntilDone:NO];
}
}];
}
-(void)exportWithSession:(AVAssetExportSession*)aexport{
[aexport exportAsynchronouslyWithCompletionHandler:^{
if (exportSession.status == AVAssetExportSessionStatusCompleted){
[self performSelectorOnMainThread:@selector(didExportedToURL:) withObject:outputhURLBuff waitUntilDone:NO];
}else{
[self performSelectorOnMainThread:@selector(didFailedToExportToURL:) withObject:outputhURLBuff waitUntilDone:NO];
}
}];
}
EDIT: When logging progress and status it always shows progress of 0.0 and status of AVAssetExportSessionStatusUnknown
Upvotes: 1
Views: 422
Reputation: 61
I think you should be checking "aexport.status" instead of "exportSession.status"
Upvotes: 1