gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:16 24 4
gpt4 key购买 nike

我正在使用以下代码将 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com