Sto provando a riprodurre un file MP3 (funziona quando viene riprodotto tramite VLC/iTunes) quando si preme un pulsante. Ecco il mio codice:Errore OSStatus 2003334207 quando si utilizza AVAudioPlayer
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 is \(url)")
audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &err)
if audioPlayer == nil {
if let e = err {
println(e.localizedDescription)
}
}
audioPlayer.delegate = self
audioPlayer.prepareToPlay()
audioPlayer.play()
}
Ecco il log:
now playing
The url is Optional(file:///var/mobile/Containers/Data/Application/4747A71E-A63F-4EFC-B2DF-8B361361080B/Documents/serial-s01-e12.mp3)
The operation couldn’t be completed. (OSStatus error 2003334207.)
fatal error: unexpectedly found nil while unwrapping an Optional value
La EXC_BREAKPOINT
accade sul audioPlayer.delegate = self
.
Altre discussioni su StackoOverflow non aiutano. Qualche idea? Grazie
Modifica: ho provato passando un localURL a contentsOfURL (invece di un oggetto CDEpisode) e non riesce ancora.
ho guardato il codice di errore e 2.003.334,207 mila dà the localizedDescription "L'operazione non può essere completata". Nella mia app stavo cercando di accedere a un file che non esisteva. – Unome