gpt4 book ai didi

ios - 错误域=NSOSStatusErrorDomain 代码=1954115647 "(null)"

转载 作者:搜寻专家 更新时间:2023-10-31 19:37:16 24 4
gpt4 key购买 nike

所以我有一个 AVAudioPlayer,有时它工作得很好,但有时它会打印错误“Error Domain=NSOSStatusErrorDomain Code=1954115647”(null)”。这是代码:

override func viewDidLoad() {
super.viewDidLoad()
downloadFileFromURL(url: URL(string: mainPreviewURL)!)
}

func downloadFileFromURL(url: URL) {
var downloadTask = URLSessionDownloadTask()
downloadTask = URLSession.shared.downloadTask(with: url, completionHandler: {
customURL, response, error in

self.play(url: customURL!)
})
downloadTask.resume()
}

func play(url: URL) {
do {
player = try AVAudioPlayer(contentsOf: url)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
player!.prepareToPlay()
player!.play()
} catch {
print(error)
}
}

最佳答案

让你的 do 语句中的代码看起来像这样:

    let songData = try NSData(contentsOfURL: songURL!, options: NSDataReadingOptions.mappedIfSafe)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVAudioPlayer(data: songData!, fileTypeHint: AVFileTypeMpegLayer3)
player!.prepareToPlay()
player!.play()

关于ios - 错误域=NSOSStatusErrorDomain 代码=1954115647 "(null)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41981498/

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