I am making a video app where I create a new video using AVAssetExportSession. While the video is being created I want to give the user ability to cancel video creation. The problem I have is that I do not know how can I send a cancellation request to AVAssetExportSession as I assume it's running on the main thread. Once it starts I have no idea how can I send a stop request?
I tried this but it doesn't work
- (IBAction) startBtn
{
....
// Export
exportSession = [[AVAssetExportSession alloc] initWithAsset:[composition copy] presetName:AVAssetExportPresetHighestQuality];
[exportSession setOutputFileType:@"com.apple.quicktime-movie"];
exportSession.outputURL = outputMovieURL;
exportSession.videoComposition = mainComposition;
//NSLog(@"Went Here 7 ...");
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status])
{
case AVAssetExportSessionStatusCancelled:
NSLog(@"Canceled ...");
break;
case AVAssetExportSessionStatusCompleted:
{
NSLog(@"Complete ... %@",outputURL); // moview url
break;
}
case AVAssetExportSessionStatusFailed:
{
NSLog(@"Faild=%@ ...",exportSession.error);
break;
}
case AVAssetExportSessionStatusExporting:
NSLog(@"Exporting.....");
break;
}
}];
}
- (IBAction) cancelBtn
{
exportSession = nil;
}