我正在使用我的应用程序中的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"]]]];
它也不起作用。即使我尝试将视频文件添加到沙箱中的资产 - 结果也是一样的。
我甚至尝试过使用AVURLAsset
,但资产也总是空着。我需要它在它们之间混合两个音频文件,然后将它与录制的视频合并。如果我可以在没有AVAssets的情况下做到这一点,还有另一种方法,如果你告诉我,我将不胜感激。或者可能还有其他功能吗?
答案 0 :(得分:2)
使用URLWithString
选择器为audioAsset2创建第二个URL。您的第一个资源已正确加载,因为您使用了fileURLWithPath
选择器。
如果要在给定的URL上加载文件,请始终使用fileURLWithPath
选择器创建NSURL对象。
所以,试试吧:
AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]];