[英]How to play iPhone media audio from documentdirectory in AKPlayer
I was previously playing the local audio to calculate frequency it worked fine, now I need to implement it by taking audiofile from document directory of user's iPhone. 我之前正在播放本地音频以计算它工作正常的频率,现在我需要通过从用户iPhone的文档目录中获取audiofile来实现它。
Code I tried: 我试过的代码:
let audioFileName = getDocDirectory().appendingPathComponent(filename)
print ("\(audioFileName)")
let player = AKPlayer(url: audioFileName)
let tracker = AKFrequencyTracker(player)
it's throwing null error on tracker as for player is null. 它在跟踪器上抛出null错误,因为玩家为空。
Two solutions combined fixed my problem. 两个解决方案相结合解决了我 1- Setting category to .playAndRecord instead of .play 1-将类别设置为.playAndRecord而不是.play
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default)
2- Setting number of channels from 1 to 2 in record Settings. 2-在记录设置中设置从1到2的通道数。
[AVFormatIDKey: kAudioFormatAppleLossless,AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue,
AVEncoderBitRateKey: 320000,
AVNumberOfChannelsKey: 2,
AVSampleRateKey: 44100.2] as [String: Any]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.