0

I'm trying to save a music from the iPod library in my app and be able to use it later. I've used the media picker to get the music URL, but I don't know how to save it in my app and play it later. Here is the code that I have used to get the music URL:

@IBAction func music(sender: AnyObject) {
    var picker = MPMediaPickerController(mediaTypes: MPMediaType.Music)
    picker.delegate = self
    picker.allowsPickingMultipleItems = false
    picker.prompt =  NSLocalizedString("Select one music", comment: "")
    self.presentViewController(picker, animated: false, completion: nil)

}

func mediaPicker(mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
    var url = NSURL()

    let items = mediaItemCollection.items
    for item in items {
       url = item.assetURL!
    }

    self.dismissViewControllerAnimated(true, completion: nil)
}
func mediaPickerDidCancel(mediaPicker: MPMediaPickerController) {

   mediaPicker.dismissViewControllerAnimated(true, completion: nil)
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Theilya
  • 69
  • 11

0 Answers0