Reputation: 1
I am trying to store an audio file in an iPhone app.
Is it possible to do this with SQLite?
Please give me suggestions.
Upvotes: 0
Views: 735
Reputation: 9212
You can save the audio data using a BLOB
in sqlite
Edit:
You can for instance define the following in your database schema:
CREATE TABLE audio (
id BIGINT PRIMARY KEY,
rawaudio BLOB
);
In your code you will then just have to store the raw data of your audio into the rawaudio
field in the audio
table.
Upvotes: 1
Reputation: 1742
Depending on the size of your audio files, BLOBs could work or you could just write them to disk and keep track of them somewhere.
I had a similar issue where I needed to pull down remote audio files and store them on the device. I used CoreData for keeping a searchable index of where all the files were stored then would just open up the file using the path that was provided for that core data item.
Core Data is a bit wonky to work with at first, but once you wrap your head around it is pretty nice. I used mogenerator for all of my models, which will run scripts on your core data models to create all the boilerplate code for you.
Upvotes: 0
Reputation: 5055
It's possible, but probably not the best idea. Instead, add the file as a resource in the application, and then store the name of the file in the DB, not the file itself. That way, you can update the file whenever and however you want.
Upvotes: 1
Reputation: 21893
Do you WANT to use SQLite, or is that a stab at answering the main question? Because if "with SQLite" isn't a requirement, this is simple. Just stick the file in your "Resources" group in XCode. It'll end up in your application bundle.
Upvotes: 1
Reputation: 938
You can indeed use BLOB data type if you want to store the audio file in the SQLite.
You could also just store it in a directory and access it directly.
It depends how you want to use your audio file and if it might change often.
Upvotes: 1
Reputation: 150615
Are you trying to do this while building the app or while it is running?
Cocoa-Touch provides persistence support through SQLite or Core-Data if you want to look at those technologies.
Upvotes: 0