swift - 斯威夫特:操作无法完成。(OSStatus 错误 2003334207。)
问题描述
我正在尝试运行一些音频,但我不断收到此错误。操作无法完成。(OSStatus 错误 2003334207。)
func fu(){
let randomCode = Int.random(in: 0...5000)
let randomString = randomCode.description
let session = URLSession.shared
let url = URL(string: "http://127.0.0.1:5000/\(randomString)")!
let task = session.dataTask(with: url, completionHandler: { data, response, error in
// Check the response
print(error)
print(response)
})
task.resume()
let downloadTask = URLSession.shared.downloadTask(with: url) {
urlOrNil, responseOrNil, errorOrNil in
// check for and handle errors:
// * errorOrNil should be nil
// * responseOrNil should be an HTTPURLResponse with statusCode in 200..<299
guard let fileURL = urlOrNil else { return }
do {
let documentsURL = try
FileManager.default.url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false)
let savedURL = documentsURL.appendingPathComponent(fileURL.lastPathComponent)
print(savedURL)
try FileManager.default.moveItem(at: fileURL, to: savedURL)
} catch {
print ("file error: \(error)")
}
}
downloadTask.resume()
print("cool")
play(url:url)
}
func play(url:URL) {
print("playing \(url)")
do {
var player = try AVAudioPlayer(contentsOf: url)
player.prepareToPlay()
player.volume = 1.0
player.play()
print("IT WORKED?!?!?!?!?!")
} catch let error as NSError {
//self.player = nil
print(error.localizedDescription)
} catch {
print("AVAudioPlayer init failed")
}
}
我知道这是我的音频部分的错误,但我不明白。我包含了我的大部分代码,因为请求部分获取了我从中播放的文件。
任何帮助,将不胜感激。
编辑我想我可能还需要提到在上述错误消息之前我还得到插件] AddInstanceForFactory: No factory registered for id
解决方案
推荐阅读
- android-ndk - libreactnativejni.so 在 64 位 android ndk (linux) 上构建为 elf32-i386
- .htaccess - 使用 .htaccess 清理一些动态生成的 URL
- python - Python 闹钟不会坏
- r - 当我知道它是 TRUE 时,%in% 返回 FALSE
- sql - 选择 SQL 中特定格式的列条目
- php - Laravel Mcamara\LaravelLocalization 在包中使用时出错
- ios - 如何有效且明确地停止 AudioKit 输入和输出?
- xamarin - 在后台应用程序时如何在 Xamarin iOS 中显示徽章计数
- sql - 如何让这个查询正常工作?
- botframework - 在 Skype 机器人上提示用户位置