我使用AVAudioPlayer录制和播放声音,在模拟器中一切正常,但在设备上,例如,从播放第五张唱片开始,它给出错误“打开失败”。(OSStatus错误1685348671。)”
我把音频格式从m4a改成了caf,控制台没有给予出错误,但是下一次播放仍然没有声音。我的代码:
func playByUrl(url: String) {
let audioFilename = getDocumentsDirectory().appendingPathComponent("\(url).m4a")
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVAudioPlayer(contentsOf: audioFilename, fileTypeHint: AVFileType.caf.rawValue)
guard let player = player else { return }
player.prepareToPlay()
player.play()
} catch let error {
print(error.localizedDescription)
}
}
字符串
1条答案
按热度按时间ffvjumwh1#
字符串
在录制设置用户语音时检查此代码
型
然后运行录音的播放声音
型
我希望它能解决你的问题