Devang
Devang

Reputation: 11338

iPhone : How to call other method from [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { }

I am using following code to combine .mp4 and .caf into .mov. (Note : I know how to play video so dont give code for that)

 AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition 
                                                                      presetName:AVAssetExportPresetPassthrough];  //AVAssetExportPresetPassthrough 

NSString* videoName = @"export.mov";

NSString *exportPath = [document stringByAppendingPathComponent:videoName];
NSURL    *exportUrl = [NSURL fileURLWithPath:exportPath];
NSLog(@"Export : %@",exportUrl);

if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) 
{
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}

_assetExport.outputFileType = AVFileTypeQuickTimeMovie;//@"com.apple.quicktime-movie";
NSLog(@"file type %@",_assetExport.outputFileType);
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;

[_assetExport exportAsynchronouslyWithCompletionHandler:
 ^(void ) {  
     switch (_assetExport.status) 
     {
         case AVAssetExportSessionStatusCompleted:
             //   export complete 

             NSLog(@"Export Complete");
       ------>>> // From Here I want play movie using MPMoviePlayerController.<<<--------- 


             break;
         case AVAssetExportSessionStatusFailed:
             NSLog(@"Export Failed");
             NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);

             //                export error (see exportSession.error)  
             break;
         case AVAssetExportSessionStatusCancelled:
             NSLog(@"Export Failed");
             NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);

             //                export cancelled  
             break;

     }


 }       

 ];

So for playing video I called other method [self playVideo] but its not playing.

I am trying to use this approach b'coz [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { } will use other thread to export video.

If I try to call [self playVideo] after the above code. It will not get video b'coz the video is still creating under the above method.

I have also tried to notify from the AVAssetExportSessionStatusCompleted but its not playing video.

So my question is How can I play video from that method? Or How can switch control to main thread so I can play video successfully?

Upvotes: 2

Views: 1136

Answers (1)

malhal
malhal

Reputation: 30746

like this:

[self performSelectorOnMainThread:@selector(playVideo) withObject:nil waitUntilDone:NO];

Upvotes: 6

Related Questions