OSStatus error 2003334207 when using AVAudioPlayer

前端 未结 7 1402
野的像风
野的像风 2021-01-17 13:10

I am trying to play an MP3 file (works when played via VLC/iTunes) when a button is pressed. Here is my code:

     var audioPlayer: AVAudioPlayer!
     @IBAc         


        
7条回答
  •  梦谈多话
    2021-01-17 13:30

    This is probably caused by trying to load a file that doesn't exist. If that helps someone adding the call to url.checkResourceIsReachable() will log more descriptive message.

    Example code:

        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)")
        }
    

提交回复
热议问题