I need to download an .mp3 audio file from a server to save in my app and play it without downloading, exactly like the screenshot below, with a progress bar for the download (I found this in the App Store). Can anyone help me to do this in my app, with source code?
Any help will be appreciated! Thanks in advance!
I used NSURLConnection
but it does not really work for me.
Here is the screenshot of what I am trying to do.
This questions discusses what you're looking for
Edit:
If you want to download a file THEN play it, what you need to do is:
use an NSURLConnection to download the file to the disk - this link discusses saving large files (i wouldn't keep 2-5mb's in the memory when i don't need them even thought it will probably work).
, than an AVAudioPlayer to play it - check this out.
Edit 2:
For the cancel button, it should practically just call the [NSURLConnection cancel] method and do whatever other finishing up your download class is gonna need...
For the progress bar, in the NSURLConnectionDelegate method didReceiveResponse, you take the NSURLResponse, cast it to a NSHTTPURLResponse, and retrieve the size of the file you're downloading using the expectedContentLength method.
And then in each call to the NSURLConnection:didRecieveData method you count the incoming bytes using [data length] method, divide it by the expectedContentLength from the previous URL response and that's the float the represents your progress that you pass to the progress view's progress property
Yes,first one.I wana download the file in my app and show it in table view then play it after download it. – DAVEd Apr 11 '11 at 14:34