views:

5991

answers:

2

Hi

I want to save an audio file to the Documents folder of my application while one of the classes in my app is streaming it. How can I do this?

Is it possible to save the streamed audio directly to an mp3? (if the audio file being streamed is an mp3 or I have to use caf?)

Thanks.

Edit: What if I am running the save in another thread and the user exits the application? I know an app cannot run in the background in an iPhone, but is there any way I can stop the download and remove the partially saved file when the user exits the app? Can I get an exit signal inside a class or in a delegate for NSURLConnection?

+1  A: 

If you are using the NSURLConnection or CFNetwork to download the file you can save it in the connectionDidFinishLoading delegate.

Take a look at Matt Gallaghers Streaming and playing an MP3 stream

catlan
I have seen Matt's example. Thats where I got the streaming working :) But the tut shows how to stream audio. And when streaming, the data might not come sequentially. I want to get all the data into a local file (I'm not sure if we can directly put the data into an mp3 file!)
lostInTransit
A: 

If you want to clean up your partially saved file on exit,
you could do worse than doing it from

- (void)applicationWillTerminate:(UIApplication *)application

in your app controller.

Rhythmic Fistman