views:

48

answers:

2

i'd like to have the user tap a cell in the tableview and hear audio. the information for the cell is loaded from core data, so i'm assuming i put the path to the audio file in core data as an attribute with type 'string'.

i am completely lost as to where to go from here. how do i call the path? after a lengthy search, i haven't found much on the topic so any help is greatly appreciated.

A: 

Your question is quite wide. The best way for you to get started is to work through Apple's avTouch example. It will show you how to load and play audio files.

Run Loop
avtouch teaches you how to playback one audio file by calling it directly in the view controller. i am trying to call the audio from the managed object in core data. i am able to do this with xml, json, and plist, but core data is a new and very different world for me. i'd like to make it access files (audio for sure, maybe even images)... not just strings, numbers, etc.
Chunjai
You say you want to call the audio from core data, yet in your original question you say you only call the audio path from core data. Which is it?
Run Loop
oh for sure. i actually don't know what i want there... basically whatever works best. i want to call audio in whatever which way. i'm thinking the path would be best.
Chunjai
You really need to work through one of Apple's Core Data examples. If you combine that with the avTouch example, you will be able to achieve what you want. The easiest way for you would be to just store the path in Core Data and leave the audio files in the main bundle.
Run Loop
+1  A: 

You should store just the file name in the managed object and then reconstruct the file path each time.

In iOS the name of the app's directory is just a UUID and it is different on every install. Further, the system may change the directories UUID without warning. This is part of the security system.

Suppose you wanted to put the audio files in a directory called AudioFiles in the Library directory. You would do something like this:

NSString *fileName=//... file name from the managed object
NSArray *libraryPaths=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libPath=[libraryPaths objectAtIndex:0];
NSArray *components=[NSArray arrayWithObjects:libPath,@"AudioFiles",fileName,nil];
NSString *theAudioFilePath=[NSString pathWithComponents:components];

See Low-Level File Management Programming Topics:Standard System Directories

Depending on how you play the audio files, you may need to convert the file path to a file URL.

TechZen
to clarify, the NSString *fileName is the folder i am tossing my audio files into? i am going for a different audio file (a quick spoken phrase) for every cell. this means i'd have a good amount of audio files in the AudioFiles directory... upwards of 100. should i be going through a plist? perhaps i'm going about this the wrong way and should be creating a custom atomic store.
Chunjai
No, the fileName is the name of the audio file. "AudioFiles" is the name of the folder. The above code presumes that the folder already exist.
TechZen
It is common to mix Core Data and independent media files. Although you can store audio and images in Core Data, it is more efficient to leave them as independent files so there are a lot of app designs that mix the two. For display in the table, its easier to store the info about the audio file (name, timestamp etc) in Core Data and then just load the actual file independently.
TechZen