我正在制作一个视频应用程序,在那里我创建一个新的视频使用AVAssetExportSession。当视频被创建时,我想给用户取消视频创建的能力。我遇到的问题是,我不知道如何向AVAssetExportSession发送取消请求,因为我假设它在主线程上运行。一旦启动,我就不知道如何发送停止请求了?
我试过了,但没有用
- (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;
}发布于 2013-11-17 13:57:59
您可以通过向导出会话发送消息cancelExport来取消它。
要做到这一点,您只需要拥有一个ivar (或属性),它保存当前活动的导出会话:
@property (nonatomic, strong) AVAssetExportSession* exportSession;初始化属性:
- (IBAction) startBtn {
if (self.exportSession == nil) {
self.exportSession = [[AVAssetExportSession alloc] initWithAsset:[composition copy]
presetName:AVAssetExportPresetHighestQuality];
...
[self.exportSession exportAsynchronouslyWithCompletionHandler:^{
self.exportSession = nil;
....
}];
}
else {
// there is an export session already
}
}为了取消会议:
- (IBAction) cancelBtn
{
[self.exportSession cancelExport];
self.exportSession = nil;
}提示:为了获得更好的用户体验,您应该相应地禁用/启用“取消”和“开始导出”按钮。
https://stackoverflow.com/questions/20031303
复制相似问题