Search code examples
iosmpmediaitemmpmediapickercontrollerswift2

How to get file location of an song in iPod library in iOS


I have the reference of a MPMediaItem when user selects an audio from the iPod library. I am getting the asset url of that item by using

     let url = item.valueForProperty(MPMediaItemPropertyAssetURL)

But this is not giving me the exact physical location of the file, instead it is giving me an url w.r.t iPod library.

ipod-library://item/item.mp3?id=1840064795502796074

Is there a way to get the physical url of a song from iPod library?

EDIT - actually I want to extract NSData from the physical file and send it to my backend server, so i need the physical file URL and not the relative URL


Solution

  • Due to copyright protection you can only play songs from music library. You can't access row audio file! But there are some tricks that can help like you can export music because you can do mixing type of stuff and after creating your new edited file you have new copy of your music file and you can send it I thing, but can't send directly from library like you send photo and video! You have to export it with export session first!

    Refer this so post for that!

    You should refer Apple sample code for that

    And this so post and this tutoria also may helpful to you!