gpt4 book ai didi

ios - 使用 AVAudioPlayer 时 OSStatus 错误 2003334207

转载 作者:IT王子 更新时间:2023-10-29 05:36:27 25 4
gpt4 key购买 nike

我正在尝试在按下按钮时播放 MP3 文件(通过 VLC/iTunes 播放时有效)。这是我的代码:

     var audioPlayer: AVAudioPlayer!
@IBAction func playEpisode(sender: AnyObject) {
println("now playing")
let indexPath = NSIndexPath(forRow: sender.tag, inSection: 0)
let data: CDEpisode = fetchedResultsController.objectAtIndexPath(indexPath!) as! CDEpisode
var err: NSError?
let url = NSURL(string: data.localPath)
println("The url is \(url)")

audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &err)
if audioPlayer == nil {
if let e = err {
println(e.localizedDescription)
}
}
audioPlayer.delegate = self
audioPlayer.prepareToPlay()
audioPlayer.play()
}

这是日志:

now playing
The url is Optional(file:///var/mobile/Containers/Data/Application/4747A71E-A63F-4EFC-B2DF-8B361361080B/Documents/serial-s01-e12.mp3)
The operation couldn’t be completed. (OSStatus error 2003334207.)
fatal error: unexpectedly found nil while unwrapping an Optional value

EXC_BREAKPOINT 发生在 audioPlayer.delegate = self 上。

StackoOverflow 上的其他线程没有帮助。有任何想法吗?谢谢

编辑:我已经尝试将 localURL 传递给 contentsOfURL(而不是 CDEpisode 对象),但它仍然失败。

最佳答案

这可能是由于试图加载一个不存在的文件造成的。如果这有助于某人添加对 url.checkResourceIsReachable() 的调用,将记录更多描述性消息。

示例代码:

    do {
let url = URL(fileURLWithPath: dbObject.path)
let isReachable = try url.checkResourceIsReachable()
// ... you can set breaking points after that line, and if you stopped at them it means file exist.
} catch let e {
print("couldnt load file \(e.localizedDescription)")
}

关于ios - 使用 AVAudioPlayer 时 OSStatus 错误 2003334207,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29088594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com