作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用以下代码将 .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/
我是一名优秀的程序员,十分优秀!