OSStatus error 2003334207 when using AVAudioPlayer

前端 未结 7 1244
野的像风
野的像风 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:39

    You're checking if audioPlayer is nil but then you go on to use it as if it wasn't anyway. You probably want something like:

    if audioPlayer == nil {
        if let e = err {
            println(e.localizedDescription)
        }
    } else {
        audioPlayer.delegate = self
        audioPlayer.prepareToPlay()
        audioPlayer.play()
    }
    

    And do something to actually handle the error case rather than just printing the error.

提交回复
热议问题