Objective c 使用AvassessionExport不断获取进度信息
我有一个问题,我正在使用AvassessionExport进行一些视频转换。 我一直试图在UIProgressView上获取进度信息,但我似乎无法用这组代码实现这一点。我能得到关于如何实现这一目标的建议吗 (看注释代码,这就是我更新进度条的方式,但它工作不好)Objective c 使用AvassessionExport不断获取进度信息,objective-c,ios,avfoundation,Objective C,Ios,Avfoundation,我有一个问题,我正在使用AvassessionExport进行一些视频转换。 我一直试图在UIProgressView上获取进度信息,但我似乎无法用这组代码实现这一点。我能得到关于如何实现这一目标的建议吗 (看注释代码,这就是我更新进度条的方式,但它工作不好) NSArray*compatiblePresets=[AVAssetExportSession exportPresetsCompatibleWithAsset:composition]; if([compatiblePresets包含对
NSArray*compatiblePresets=[AVAssetExportSession exportPresetsCompatibleWithAsset:composition];
if([compatiblePresets包含对象:AVAssetExportPresetHighestQuality]){
AVAssetExportSession*exportSession=[[AVAssetExportSession alloc]
initWithAsset:组合预设名称:AVAssetExportPresetHighestQuality];
nsindepath*indepath=[nsindepath indexPathForRow:0第1节];
UITableViewCell*单元格=(UITableViewCell*)[(UITableView*)self.view单元格for行索引路径:indexPath];
//UIProgressView*prog=[[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
//[cell.contentView addSubview:prog];
//
exportSession.outputURL=[NSURL fileURLWithPath:[[ShowDAO userDocumentDirectory]stringByAppendingString:exportFilename]];
exportSession.outputFileType=AVFileTypeQuickTimeMovie;
CMTime start=CMTimeMakeWithSeconds(0,1);
CMTime duration=CMTimeMakeWithSeconds(1000,1);
CMTimeRange范围=CMTimeRangeMake(开始、持续时间);
exportSession.timeRange=范围;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
开关([exportSession状态]){
案例AvassetExportSessionStatus已完成:
NSLog(“导出完成”);
[DSBezelActivityView removeViewAnimated:是];
//删除未使用的视频文件
[[NSFileManager defaultManager]removeItemAtPath:[[ShowDAO userDocumentDirectory]stringByAppendingString:videoFilename]错误:NULL];
打破
案例AvassetExportSessionStatus失败:
NSLog(@“导出失败:%@,[[exportSession error]localizedDescription]);
打破
案例AvassetExportSessionStatus取消:
NSLog(“出口取消”);
打破
违约:
打破
}
}];
//当(exportSession.progress您正在使用注释代码阻塞主线程。您应该将exportSession设置为正在执行此操作的类的属性。然后我建议使用一个NSTimer,它定期调用类方法,然后更新progressView,直到导出会话完成。我希望这是清楚的,如果不是,我可以提供删除一些代码。这就是我正在做的
BOOL goOnFlag = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
int count = 0;
while(fabs(avAssetExportSession.progress - 1.0)>0.01&&goOnFlag){
NSLog(@"loading... : %f",avAssetExportSession.progress);
sleep(1);
if(avAssetExportSession.progress==0)
count++;
if(count>8){
[self async_main:^{
[avAssetExportSession cancelExport];
goOnFlag = NO;
NSLog(@"save failed");
}];
}
}
});
BOOL goOnFlag = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
int count = 0;
while(fabs(avAssetExportSession.progress - 1.0)>0.01&&goOnFlag){
NSLog(@"loading... : %f",avAssetExportSession.progress);
sleep(1);
if(avAssetExportSession.progress==0)
count++;
if(count>8){
[self async_main:^{
[avAssetExportSession cancelExport];
goOnFlag = NO;
NSLog(@"save failed");
}];
}
}
});