1

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.

Screenshot of download with progress bar

jscs
  • 63,694
  • 13
  • 151
  • 195
DAVEd
  • 51
  • 2
  • 8
  • 2
    What problems were you having with NSURLConnection? – Twelve47 Apr 11 '11 at 11:59
  • I agree with @Twelve47. Your question should be about the error you are getting when using NSURLConnection. Otherwise @Zaky has provided a link below which I believe will take you in the right direction. – Black Frog Apr 11 '11 at 12:24
  • possible duplicate of [downloading mp3 file from server in iphone programing.](http://stackoverflow.com/questions/5602409/downloading-mp3-file-from-server-in-iphone-programing) – Brad Larson Apr 20 '11 at 15:19

2 Answers2

3

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

Community
  • 1
  • 1
Zaky German
  • 14,324
  • 4
  • 25
  • 31
  • @DAVE not sure what you mean, but if you've found what you're looking for, you're welcome to click the "V" button next to the answer to accept it :) – Zaky German Apr 11 '11 at 14:12
  • I use this code in this site but it does not save the file and has not progress view. please help with sample code.thankx http://www.ifans.com/forums/showthread.php?t=169611 – DAVEd Apr 11 '11 at 14:21
  • @DAVE do you want to first download than play or download WHILE playing the file? The first is easy and i'll describe if you want, the other (or both save and play while saving) is hard and partly (besides the saving the file to disk part) described in the link i gave you. – Zaky German Apr 11 '11 at 14:27
  • 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
  • @DAVE also if you've found the answer helpful, please press the "V" button next to it ;) – Zaky German Apr 11 '11 at 15:05
  • what about progress view with cancel button. – DAVEd Apr 11 '11 at 17:00
  • please do you have sample code to do that coz I am not perfect in programing but I can understand the code if I read it. I appreciate ur help. – DAVEd Apr 12 '11 at 17:13
2

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