iPhone SDK:Saving a streamed audio file to Documents folder

大城市里の小女人 提交于 2019-11-29 23:36:35

问题


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:


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




回答2:


(void)applicationWillResignActive:(UIApplication *)application
{

}

Write your code in the above method in App delegate file.




回答3:


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.



来源:https://stackoverflow.com/questions/423536/iphone-sdksaving-a-streamed-audio-file-to-documents-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!