【问题标题】:AVAsset tracks is emptyAVAsset 轨道为空
【发布时间】: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


    【解决方案1】:

    AVAsset 加载不是瞬时的。您需要等待数据可用。示例:

    AVAsset *test = [AVURLAsset URLAssetWithURL:firstAudioFileLocation options:nil];
    [test loadValuesAsynchronouslyForKeys:@[@"playable",@"tracks"] completionHandler:^{
    
        // Now tracks is available
        NSLog(@" total tracks %@", test.tracks);
    }];
    

    更详细的例子可以在in the documentation找到。

    【讨论】:

    • 这有很大帮助,但它仍然返回一个空数组。在使用 AVKeyValueStatus 查看它之后,似乎 AVAsset 不支持线性 PCM?我是否有误解,是否有支持的合成类型列表?
    • 您的 .pcm 文件是原始文件吗?这不是受支持的格式(奇怪的是),如果你在上面放一个 wav 标题,它就会起作用。
    • 请注意,此过程适用于 .mp4 视频,但不适用于 HLS(.m3u8) 视频。 stackoverflow.com/questions/52409687/…
    猜你喜欢
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    相关资源
    最近更新 更多