samedi 9 juillet 2016

Audio file not playing from document directory


i have an audio file located in Document Directory and its not playing but I didn't get any error or crash. I'm really stuck at this situation, referred many SO links but none of them solved my issue.

  var myPlayer = AVAudioPlayer()

    let fileManager = NSFileManager.defaultManager()

    let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    if let documentDirectoryURL: NSURL = urls.first {
    let soundURL = documentDirectoryURL.URLByAppendingPathComponent("09.mp3")
        do {
            myPlayer = try AVAudioPlayer(contentsOfURL: soundURL)
            myPlayer.delegate = self
            myPlayer.prepareToPlay()
            myPlayer.play()
        } catch let error as NSError {
            NSLog("Unresolved error (error.debugDescription)")
            // SHOW ALERT OR SOMETHING
        }
    }

Aucun commentaire:

Enregistrer un commentaire