Search code examples
iosmp3

iOS download mp3 to app's sandbox


i want to play mp3 on my iphone app. I can streaming the mp3 from my server now (by using MPMoviePlayerViewController). However, i want to add the function that enable the user to download the mp3, then play it locally when there's no internet connection.

There's an app called Elevation does exactly the same thing. It will download the mp3 into the app's sandbox (not the ipod library). And the users can delete it later if they want. Anyone know how it does that magic?

enter image description here


Solution

  • Use a NSURLConnection BUT download the files asynchronously because synchronously connections will make your UI to be frozen while downloading files. Here's a clear example of how you do it, you only need to do small changes:

    http://blog.sallarp.com/iphone-uiimage-asynchronously/

    Hope it helps.