Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a audio file programmatically?

I want to download a audio file from the following link

audio file link

I have tried the other answers that are posted in this site. But I don't want to use ASIHTTPRequest so can anyone please tell me how to download that link content to my document directory.

like image 351
surendher Avatar asked Jul 24 '12 10:07

surendher


People also ask

How do I download an audio file from a website?

Steps: Launch the Chrome browser and enter the Chrome Web Store to find Spotify & Deezer Music Downloader. Tap “Add to Chrome” option to install the extension. Go to the website and search the audio you want to download, and then click the “Download” button next to the audio to start downloading.


1 Answers

Well you could write something like this:

//Download data
NSData *data = [NSData dataWithContentsOfURL:<YOUR URL>];

//Find a cache directory. You could consider using documenets dir instead (depends on the data you are fetching)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths  objectAtIndex:0];

//Save the data    
NSString *dataPath = [path stringByAppendingPathComponent:@"filename"];
dataPath = [dataPath stringByStandardizingPath];
BOOL success = [data writeToFile:dataPath atomically:YES];
like image 186
EsbenB Avatar answered Nov 10 '22 01:11

EsbenB