Progress bar for AVAssetExportSession

后端 未结 4 608
遇见更好的自我
遇见更好的自我 2021-02-02 11:57

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

4条回答
  •  一个人的身影
    2021-02-02 12:59

    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];
        }
    }
    

提交回复
热议问题