0

I am developing an iPhone application for an audio player. I want to give some options to the user so they can listen to the song/music by streaming or they can download the audio file and store in sqlite database. I know how to stream the audio files in the app programmatically. But I don’t know how to store the downloaded audio file in sqlite database. Additionally, after storing the audio file in the sqlite DB I need to fetch the audio file and play the song. How do I fetch the audio file from sqlite DB?

This is my code for downloading the audio file.

NSURL *url = [NSURL URLWithString:@"http://www.fileurl.com/example.mp3"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadDestinationPath:[NSString stringWithFormat:@"%@",dataPath]]; 
[request setDelegate:self];
[request startAsynchronous];
mhillsman
  • 770
  • 1
  • 8
  • 26
  • i want to store audio urls in sqlite db and fetch audio urls from sqlite db.. please give me any suggestions how to do this ....thanks in advance. – user3214012 May 22 '17 at 05:46
  • you want to store audio URL or you want to to store full audio in sqilite – Anbu.Karthik May 22 '17 at 05:49
  • one more question you want to play the audio in offline or online after the fetch from local db – Anbu.Karthik May 22 '17 at 05:50
  • i want to store full audio in sqlite... if network is available i want to play in online mode. if network is not available then i want to play audio from local db... – user3214012 May 22 '17 at 05:50
  • see this link once http://stackoverflow.com/questions/1056429/how-do-i-store-audio-files-in-sqlite3-database-and-play-them-in-iphone – Anbu.Karthik May 22 '17 at 05:53

1 Answers1

1

First thing is ASIHTTPRequest is deprecated. Use it's alternative. and the method to store and play.

  • Using the method download audio and store in to document directory folder.
  • Do not full path of document directory in side the sqlite database table.
  • Just store filename of your audio in side the sqlite. because document directory folder path going to be change after close and open app so just store name in sqlite and use document directory folder path using function.
  • if you are playing audio file without download then just store the url in sqlite and play it.
Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144