OSStatus error 2003334207 when using AVAudioPlayer

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

    It looks like your trying to unwrap a variable that has a nil value. You should safely unwrap your variables to prevent this.

    if let data: CDEpisode = fetchedResultsController.objectAtIndexPath(indexPath!) as! CDEpisode
    {
        var err: NSError?
        let url = NSURL(string: data.localPath)
        println("The url is \(url)")
    
        //rest of code
    }
    

    You will still need to figure out why it is returning nil but this is a safer way to unwrap variables and prevent crashing as there would need to be more context to resolve that issue.

    Some questions to look into:

    • Are you sure the fetchedResultsController is returning an object at all?
    • Are you sure it is of CDEpisode?

提交回复
热议问题