AVAsset' trackWithMediaType'返回一个空数组?(音频)

时间:2017-06-15 02:36:50

标签: ios audio composite avasset

我希望使用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

1 个答案:

答案 0 :(得分:0)

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