ios - OSStatus error 2003334207 when using AVAudioPlayer -


i trying play mp3 file (works when played via vlc/itunes) when button pressed. here code:

     var audioplayer: avaudioplayer!      @ibaction func playepisode(sender: anyobject) {     println("now playing")     let indexpath = nsindexpath(forrow: sender.tag, insection: 0)     let data: cdepisode = fetchedresultscontroller.objectatindexpath(indexpath!) as! cdepisode     var err: nserror?     let url = nsurl(string: data.localpath)     println("the url \(url)")      audioplayer = avaudioplayer(contentsofurl: url, error: &err)     if audioplayer == nil {         if let e = err {             println(e.localizeddescription)         }     }     audioplayer.delegate = self     audioplayer.preparetoplay()     audioplayer.play() } 

here log:

now playing url optional(file:///var/mobile/containers/data/application/4747a71e-a63f-4efc-b2df-8b361361080b/documents/serial-s01-e12.mp3) operation couldn’t completed. (osstatus error 2003334207.) fatal error: unexpectedly found nil while unwrapping optional value 

the exc_breakpoint happens on audioplayer.delegate = self.

other threads on stackooverflow not help. ideas? thanks

edit: have tried passing localurl contentsofurl (instead of cdepisode object) , still fails.

it looks trying unwrap variable has nil value. should safely unwrap variables prevent this.

if let data: cdepisode = fetchedresultscontroller.objectatindexpath(indexpath!) as! cdepisode {     var err: nserror?     let url = nsurl(string: data.localpath)     println("the url \(url)")      //rest of code } 

you still need figure out why returning nil safer way unwrap variables , prevent crashing there need more context resolve issue.

some questions into:

  • are sure fetchedresultscontroller returning object @ all?
  • are sure of cdepisode?

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -