我将两个录音(使用AVAudioRecorder
录制)合并到一个文件中。使用AVAssetExportSession
导出组合文件第一次完美运行(即只要我在当前视图控制器中)
但是当再次加载此视图(新会话)时,AVAssetExportSession exportAsynchronouslyWithCompletionHandler
:方法根本不会被调用(没有回调!)
没有错误没有什么......
我试图记录AVAssetExportSession对象,我第一次得到这个
<AVAssetExportSession: 0x155b3250, asset = <AVMutableComposition: 0x156474c0 tracks = ("<AVMutableCompositionTrack: 0x156a0bb0 trackID = 1, mediaType = soun, editCount = 0>")>, presetName = AVAssetExportPresetAppleM4A, outputFileType = (null)
这是第二次
<AVAssetExportSession: 0x1559e840, asset = <AVMutableComposition: 0x155f7f30 tracks = ("<AVMutableCompositionTrack: 0x155f0120 trackID = 1, mediaType = soun, editCount = 1>")>, presetName = AVAssetExportPresetAppleM4A, outputFileType = (null)
我注意到的唯一区别是editCount = 1件事。
我知道这听起来令人困惑,这对我来说。无论发生在什么地方?
我的代码:
AVAssetExportSession* exportSession = [AVAssetExportSession
exportSessionWithAsset:composition
presetName:AVAssetExportPresetAppleM4A];
NSLog(@"exportSession: %@", exportSession);
exportSession.outputURL = [NSURL fileURLWithPath:combined];
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusFailed:
NSLog(@"AVAssetExportSessionStatusFailed");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"AVAssetExportSessionStatusCompleted");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"AVAssetExportSessionStatusWaiting");
break;
default:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:exportSession];
});
}];
答案 0 :(得分:3)
它可能相关也可能不相关,但我在视频方面遇到了类似的问题。如果导出会话没有关于AVAsset
开始时间和持续时间的正确信息,则不会触发完成块。我找到的唯一解决方法是在将每个资产添加到合成轨道(CMTimeRangeMake()
)时为每个资产寻找少量时间。这不太理想。
答案 1 :(得分:0)
它的工作正常。
[exportSession exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
switch (exportSession.status)
{
case AVAssetExportSessionStatusFailed:
NSLog(@"AVAssetExportSessionStatusFailed");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"AVAssetExportSessionStatusCompleted");
[self exportDidFinish:exportSession];
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"AVAssetExportSessionStatusWaiting");
break;
default:
break;
}
});
}];