我在我的应用程序中使用AVAsset,遇到了下一个问题。
当我写这样的东西:

AVAsset *audioAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Hello.mp3", [[NSBundle mainBundle] resourcePath]]]];

它的工作很好。但是,当我尝试从应用程序的沙箱中的tmp目录中获取新的录制文件时,如下所示:
AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]];

它也不起作用。即使我尝试将视频文件从沙箱添加到 Assets 中,结果也一样。
我什至尝试使用AVURLAsset,但是 Assets 也总是空的。我需要它在它们之间混合两个音频文件,然后将其与录制的视频合并。如果我可以在没有AVAsets的情况下做到这一点,并且还有另一种方法,那么如果您告诉我,我将不胜感激。还是可能有其他功能?

最佳答案

使用URLWithString选择器为audioAsset2创建第二个URL。您的第一个 Assets 已正确加载,因为您使用了fileURLWithPath选择器。

如果要在给定URL上加载文件,请始终使用fileURLWithPath选择器创建NSURL对象。

因此,只需尝试:

AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]];

10-08 08:46