开发者

How can I store an audio file in an iPhone app?

I am trying to store an audio file in an iPhone app.

Is it possible to do this with SQLite?

开发者_开发知识库

Please give me suggestions.


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.


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.


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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜