本质上,我希望连接AVAsset文件。我有一个粗略的想法,做什么,但我正在努力加载音频文件。
我可以用一个AVAudioPlayer播放文件,我可以通过我的终端在目录中看到它们,但是当我尝试用AVAssetURL加载它们时,它总是返回一个空数组来查找曲目。
我使用的URL:
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文件扩展名。
.PCM似乎不支持AVAsset,这个页面也有很大的帮助。https://developer.apple.com/documentation/avfoundation/avfiletype
发布于 2017-12-14 15:21:21
AVAsset负载不是瞬时的。您需要等待数据可用。示例:
AVAsset *test = [AVURLAsset URLAssetWithURL:firstAudioFileLocation options:nil];
[test loadValuesAsynchronouslyForKeys:@[@"playable",@"tracks"] completionHandler:^{
// Now tracks is available
NSLog(@" total tracks %@", test.tracks);
}];一个更详细的例子可以找到在文件中。
https://stackoverflow.com/questions/47816292
复制相似问题