Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - How to download Audio file

Tags:

ios

download

I am currently working on an app which requires me to download audio files from web server. The URL would be something like this: http://universalstreamsolution.com/Samonas/test1.m4a .

Any suggestions on what I should do to be able to reach my goal?

like image 323
Sync Mnemosyne Avatar asked Feb 03 '26 16:02

Sync Mnemosyne


2 Answers

if you need the data in the format of data, you can use the data class to download the data with the method to download the data from an URL:

[NSData dataWithContentsOfURL:URL]

also consider the answer there for playing an NSData as audio: How to play an audio if we pass NSData?

like image 159
Lorenzo Boccaccia Avatar answered Feb 05 '26 05:02

Lorenzo Boccaccia


[NSData dataWithContentsOfURL:URL] works but it causes UI block so that user can not interact with device till the file is completely downloaded. Such a bad user experience. I suggest using NSURLSession with this great tutorial: http://www.raywenderlich.com/51127/nsurlsession-tutorial

like image 24
Thanh-Nhon Nguyen Avatar answered Feb 05 '26 04:02

Thanh-Nhon Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!