首页 > 解决方案 > 斯威夫特:操作无法完成。(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

标签: swiftavfoundation

解决方案


推荐阅读