【发布时间】:2018-05-28 17:11:37
【问题描述】:
基本上我希望连接AVAsset 文件。我对该怎么做有一个粗略的想法,但我正在努力加载音频文件。
我可以使用AVAudioPlayer 播放文件,我可以通过终端在目录中看到它们,但是当我尝试使用AVAssetURL 加载它们时,它总是返回一个空的曲目数组。
我正在使用的网址:
NSURL *firstAudioFileLocation = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@%@", workingDirectory , @"/temp.pcm"]];
结果:
file:///Users/evolve/Library/Developer/CoreSimulator/Devices/8BF465E8-321C-47E6-BF2E-049C5E900F3C/data/Containers/Data/Application/4A2D29B2-E5B4-4D07-AE6B-1DD15F5E59A3/Documents/temp.pcm
正在加载的资产:
AVAsset *test = [AVURLAsset URLAssetWithURL:firstAudioFileLocation options:nil];
但是当调用这个时:
NSLog(@" total tracks %@", test.tracks);
我的输出总是total tracks ()。
我随后将它们添加到我的AVMutableCompositionTrack 的调用最终导致应用程序崩溃,因为AVAsset 似乎没有正确加载。
我玩过其他加载资产的变体,包括:
NSURL *alternativeLocation = [[NSBundle mainBundle] URLForResource:@"temp" withExtension:@"pcm"];
以及尝试使用文档中的选项加载 AVAsset:
NSDictionary *assetOptions = @{AVURLAssetPreferPreciseDurationAndTimingKey: @YES};
如何从AVAudioRecorder 最近创建的本地资源 加载曲目?
编辑
我摸索了一下,发现我可以录制和加载 .CAF 文件扩展名。
似乎 AVAsset 不支持 .PCM,此页面也很有帮助。 https://developer.apple.com/documentation/avfoundation/avfiletype
【问题讨论】:
标签: ios objective-c avfoundation