On the iPhone, I need to get the path to the resource. Ok, I did it, but when it comes to CFURLCreateFromFileSystemRepresentation, I just don't know how to solve it. Why does this error occur? Any solution or workaround would be much appreciated. Thank you in advance.
I looked at the following examples to play audio using AudioQueue on iPhone: SpeakHere, AudioQueueTools (from the SimpleSDK directory), and AudioQueueTest. I tried to do this and this, trying to combine puzzles. Right now, I'm stuck with this. The program crashed due to an exception thrown from sndFile above.
I use AVAudioPlayer to play every sound in my iPhone games. On a real iPhone device, it turned out to be very laconic when the sound is playing, so I decided to use AudioQueue.
- (id) initWithFile: (NSString*) argv{ if (self = [super init]){ NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:argv ofType:@"mp3"]; int len = [soundFilePath length]; char* fpath = new char[len]; //this is for changing NSString into char* to match //CFURLCreateFromFileSystemRepresentation function requirement. for (int i = 0; i < [soundFilePath length]; i++){ fpath[i] = [soundFilePath characterAtIndex:i]; } CFURLRef sndFile = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *)fpath, strlen(fpath), false); if (!sndFile) { NSLog(@"sndFile error"); XThrowIfError (!sndFile, "can't parse file path"); } }
source share