是否可以在主线程上运行完成块?
例如,我有一个返回值的方法:
- (int)test
{
/* here one method is called with completion block with return type void */
[obj somemethodwithcompeltionblock:
{
/* here I am getting my Int which I want to return */
}
];
}
Run Code Online (Sandbox Code Playgroud)
但我无法看到如何从完成块中返回整数值作为此方法的结果,因为完成块在后台线程上运行.
我怎样才能做到这一点?
我正在为iPhone中的Play Station 3开发媒体服务器.
我开始知道PS3不支持.MOV文件所以我必须将其转换为Mp4或PS3支持的其他转码.
这就是我所做的,但如果我设置的文件类型与源文件不同,它会崩溃.
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
exportSession.outputFileType = AVFileTypeMPEG4;
CMTime start = CMTimeMakeWithSeconds(1.0, 600);
CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
break;
}
[exportSession release];
}];
}
Run Code Online (Sandbox Code Playgroud)
如果我在这里设置AVFileTypeMPEG4然后它崩溃,说"无效的文件类型".所以我必须将它设置为AVFileTypeQuickTimeMovie并且它给出了MOV文件.
在iOS中是否可以通过AVAssetExportSession将视频从MOV转换为Mp4 …