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

标签 iphone objective-c ios cocoa-touch

我正在使用以下代码将 .mp4.caf 组合成 .mov。 (注意:我知道如何播放视频所以不要为此提供代码)

 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;

     }


 }       

 ];

所以为了播放视频,我调用了其他方法 [self playVideo] 但它没有播放。

我正在尝试使用这种方法 b'coz [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { } 将使用其他线程导出视频。

如果我尝试在上述代码之后调用 [self playVideo]。它不会获得视频,因为视频仍在使用上述方法创建。

我也尝试从 AVAssetExportSessionStatusCompleted 通知,但它没有播放视频。

所以我的问题是如何通过该方法播放视频?或者如何将控制切换到主线程以便我可以成功播放视频?

最佳答案

像这样:

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

关于iPhone : How to call other method from [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { },我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8666075/

相关文章:

ios - UIScrollView 的 ContentView 中的 UIViewControllers?

iphone - Facebook iOS SDK - 写入状态的奇怪效果

ios - UIKeyboard 出现会触发滚动事件,然后关闭键盘

ios - 调用通知时 BAD_ACCESS

objective-c - 对不是基于字符串的字符串的 nsarray 进行排序

ios - 在 ABPeoplePickerNavigationController 中添加滑动删除功能

ios - 如何在swift 3中仅在按钮的有界区域上获取触摸事件

iphone - 从文档目录加载图像

ios - 颜色色调 UIButton 图像

iphone - 自动递增构建号xcode?