Progress bar for AVAssetExportSession

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

I've got an app that exports an AVMutableComposition into a .mov file, and I'd like for the user to see the status of the export with a progress bar the same way that you would if you sent a text message or uploaded a file.

I know how to create a progress bar when I know the duration of a task (such as playing an audio file), but since there's no set duration for the export I'm unsure how to proceed.

I've got an activity indicator currently but it doesn't provide the best user experience.

Does anyone have any pointers?

回答1:

I came up with an answer a while back so I'll post it in case it can help someone:

First, in the method in which you call AVAssetExportSession you've got to set up a timer to update your UIProgressView once you've initiated the export:

//`AVAssetExportSession` code here     self.exportProgressBarTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateExportDisplay) userInfo:nil repeats:YES]; ... 

Then you need a method to update your display taking into account that the progress property on AVAssetExportSession goes from 0 - 1:

- (void)updateExportDisplay {     self.exportProgressBar.progress = exportSession.progress;     if (self.exportProgressBar.progress > .99) {         [self.exportProgressBarTimer invalidate];     } } 


回答2:

Same issue i have faced in iOS 8.0, i resolved it using dispatch quee

- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler{  [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];  exportSession2 = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; exportSession2.outputURL = outputURL; exportSession2.outputFileType = AVFileTypeQuickTimeMovie;  [exportSession2 exportAsynchronouslyWithCompletionHandler:^(void)  {      handler(exportSession2);  }];   dispatch_async(dispatch_get_main_queue(), ^(void){        self.exportProgressBarTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateExportDisplay) userInfo:nil repeats:YES];  }); 

}



回答3:

Use below lines of code.

Reference Link : https://github.com/keijiro/iOS4BookSampleCode/blob/master/3.3.SimpleExport/Classes/SimpleExportViewController.m



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!