我正在尝试播放从iTunes API获得的音频URL。它们是m4a类型。我将URL保存为字符串,并将其发送到我的playSound函数。我看过其他出现此错误的帖子,但无法修复我的错误。
音频网址示例
我收到错误消息“错误:操作无法完成。(OSStatus错误2003334207。)”
func playSound(soundUrl: String) {
let sound = NSURL(fileURLWithPath: soundUrl)
do {
let audioPlayer = try AVAudioPlayer(contentsOf: sound as URL)
audioPlayer.delegate = self as? AVAudioPlayerDelegate
audioPlayer.prepareToPlay()
audioPlayer.play()
}catch let error {
print("Error: \(error.localizedDescription)")
}
}