2017-06-15 100 views
0

我想通过使用AVAssetExportSession来合成两个音频。当我使用AVAsset通过使用'tracksWithMediaType:AVMediaTypeAudio'来获取轨道时,我得到一个空数组。 这些音频文件由'AVAudioRecorder'记录,它们有.aac扩展名。 我用得到的代码跟踪:AVAsset'tracksWithMediaType'返回一个空数组?(音频)

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 

回答

0

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