gpt4 book ai didi

ios - AVAsset 'tracksWithMediaType'返回一个空数组?(音频)

转载 作者:行者123 更新时间:2023-12-03 01:44:54 24 4
gpt4 key购买 nike

我想使用AVAssetExportSession合成两个音频。当我使用AVAsset来通过'tracksWithMediaType:AVMediaTypeAudio'进行跟踪时,我得到了一个空数组。
这些音频文件由'AVAudioRecorder'录制,并且具有.aac扩展名。
我用来跟踪的代码:

 AVAsset * asset = [AVAsset assetWithURL:[NSURL URLWithString:model.localPath]];

NSArray * tracks = [asset tracksWithMediaType:AVMediaTypeAudio];

AVAssetTrack * track = nil;
if (tracks.count) {
track = tracks[0];
}

初始化 AVAudioRecorder的设置:
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
[audioSession setActive:YES error:nil];


NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] init];
[recordSettings setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey: AVFormatIDKey];
[recordSettings setValue :[NSNumber numberWithFloat:11025.0] forKey: AVSampleRateKey];//44100.0
[recordSettings setValue :[NSNumber numberWithInt:2] forKey: AVNumberOfChannelsKey];
[recordSettings setValue:[NSNumber numberWithInt:AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];

我也尝试其他。 mp3文件进行跟踪,但它是一个空数组。
音频文件的本地路径为:
  /var/mobile/Containers/Data/Application/DDAB48C4-A233-4B4C-B3B7-5F66AE076239/Documents/media/1497494042.aac

最佳答案

我自己找到了解决方案。
localpath错误!正确的路径应为“file:///var/mobile/Containers/Data/Application/DDAB48C4-A233-4B4C-B3B7-5F66AE076239/Documents/media/1497494042.aac”

关于ios - AVAsset 'tracksWithMediaType'返回一个空数组?(音频),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44557616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com