简体   繁体   中英

AVExportSession change view on completion

I'm having a number of related issues using AVExportSession. I'm very aware that I could be attempting this wrong, but have tried a couple of solutions to no avail.

I'm exporting a composition using AVExportSession and then using the completion handler to trigger other code once it is done (should be within 3 seconds normally). The problem comes when I want to change view on completion. For example, I have a button in a modal view that triggers the audio export, but I would like it subsequently shut the view on completion. The error message i receive is quite obvious - "This may be a result of calling to UIKit from a secondary thread."

NSURL *exportURL = [NSURL fileURLWithPath:saveSong];
exportSession.outputURL = exportURL;
exportSession.outputFileType = @"com.apple.m4a-audio";
[exportSession exportAsynchronouslyWithCompletionHandler:^{
    if (AVAssetExportSessionStatusCompleted == exportSession.status) {
        NSLog(@"AVAssetExportSessionStatusCompleted");



        [[NSNotificationCenter defaultCenter] 
         postNotificationName:@"end" 
         object:self];



    } else if (AVAssetExportSessionStatusFailed == exportSession.status) {
        // a failure may happen because of an event out of your control
        // for example, an interruption like a phone call comming in
        // make sure and handle this case appropriately
        NSLog(@"AVAssetExportSessionStatusFailed");
    } else {
        NSLog(@"Export Session Status: %d", exportSession.status);
    }
}];

My current attempt involves sending a NSNotification to close the view in an attempt to jump onto the main thread.

Very sorry if this appears unclear - part of the problem I am having in finding a solution is in expressing quite what is going wrong. I hope that by posting my fumbled attempt at a description, somebody may have exactly the right question to ask me and thus a clue to the answer!

This also occurs as an offshoot of another issue I am trying to resolve. When I start the export, I unhide an animated UIActivityView, but when trying to hide on completion, it is about 20 seconds after the completion (NSLog-ed) that the UIActivityView finally hides

solution: use [self performSelectorOnMainThread:@selector(stopActivityIndicator) withObject:nil waitUntilDone:YES];

then call my view change/activity indicator stuff from -(void)stopActivityIndicator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM