3

I am working on one application in which it requires to merge more than one videos. I am using AVExportSession to export merged video. I am also displaying progress bar for exporting video. It is running correctly.

The issue occurs when we lock the screen or put application in background mode. This time if exporting is in process, it immediately fails after putting application in background mode. I have also tried to use background task. Check below code.

if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { 
    if ([[UIDevice currentDevice] isMultitaskingSupported]) { 
        UIApplication *application = [UIApplication sharedApplication]; 
        __block UIBackgroundTaskIdentifier background_task; /
        background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
            [application endBackgroundTask: background_task]; 
            background_task = UIBackgroundTaskInvalid; 
        }];


        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{


            //START EXPORT SESSION
            [exporter exportAsynchronouslyWithCompletionHandler:^
             {


                 dispatch_async(dispatch_get_main_queue(), ^{


                     [self exportDidFinish:exporter];



                 });

             }];


            NSLog(@"Running in the background!");
            [application endBackgroundTask: background_task]; 
            background_task = UIBackgroundTaskInvalid; 


        });
    }
}

But this does not seem to work. What am I doing wrong? Any help would be appreciated.

I know it is possible to run an AVExportSession in the background as I found many apps in the app store that can do this.

Thanks in advance.

Zoltan Krix
  • 83
  • 1
  • 6
  • In what way does the background code not work? Does it still fail? What errors do you receive? – Mike Weller May 28 '13 at 13:37
  • when i return from the background the exportdidfinish method gets called where I'm tracking the export status with if statements and exporter.status == AVAssetExportSessionStatusFailed gets called. There is no error the export simply stops. I now realize that the other programs I mentioned are not continuing in the background but somehow pausing the export and continuing when you return to foreground. I'm not sure how you pause an exportsession. – Zoltan Krix May 28 '13 at 17:05
  • Were you ever able to figure this out? I'm looking to do the same thing and am also getting a failure. – user1218464 Dec 23 '14 at 23:19

1 Answers1

0

replace this code for [self exportDidFinish:exporter];

[self performSelectorOnMainThread:@selector(exportDidFinish:) withObject:exporter waitUntilDone:YES];
NANNAV
  • 4,875
  • 4
  • 32
  • 50
  • This makes no difference for me. When I enter the background the export stops and when I enter the foreground the exportdidfinish method gets called with AVAssetExportSessionStatusFailed – Zoltan Krix May 28 '13 at 17:06