[英]AVAudioPlayer fails with error “The operation couldn’t be completed. (OSStatus error 2003334207.)”
This is my code sample... for few audio files (mp4 extension) it fails with exception "The operation couldn't be completed. (OSStatus error 2003334207.)" I downloaded container from iPhone and confirmed the file exist on path 这是我的代码示例...对于少数音频文件(mp4扩展名),它会失败,但出现异常“操作无法完成。(OSStatus错误2003334207。)”。我从iPhone下载了容器,并确认文件存在于路径中
do {
audioPlayer = try AVAudioPlayer(contentsOf: url)
//guard let player = player else { return }
audioPlayer.delegate = self
audioPlayer.prepareToPlay()
audioPlayer.play()
audioPlayer.volume = 1.0
if timer != nil && timer.isValid {
timer.invalidate()
timer = nil
}
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(LynkAudioPlayer.checkPlayTime), userInfo: nil, repeats: true)
} catch let error as NSError {
print(error.description)
}
Your code looks fine. 您的代码看起来不错。 This error occurs because you are either accessing a file that is not at the specified
url
or the value is otherwise nil
after it returns. 发生此错误的原因是,您正在访问的文件不在指定的
url
或者返回的值是nil
。 Ensure you have a properly formed url for the resource accessed with AVAudioPlayer(contentsOf: url)
. 确保您具有使用
AVAudioPlayer(contentsOf: url)
访问的资源的AVAudioPlayer(contentsOf: url)
正确的AVAudioPlayer(contentsOf: url)
。 The audio data must also be in a format supported by Core Audio. 音频数据还必须采用Core Audio支持的格式。 You may want to check if
audioPlayer
is nil
after setting: 设置后,您可能要检查
audioPlayer
是否为nil
:
audioPlayer = try AVAudioPlayer(contentsOf: url)
if audioPlayer != nil {
audioPlayer.delegate = self
audioPlayer.prepareToPlay()
audioPlayer.play()
audioPlayer.volume = 1.0
} else {
//try to load a different resource?
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.