I'm using Apple's Audio Queue for playing an audio file on my computer. I've followed their guide, but I'm having a problem when I ask to the user to insert the absolute-path to research the audio file. Here there's my code. I hope you can help me... I've tried to find on Google an answer but all of them are or in Objective-C or in Swift, instead I'm programming this in C.
void getUrlofAudioFile(CBRAudioFileRef userData) {
char *filePath = NULL;
OSStatus result = noErr;
filePath = (char *)malloc(sizeof(char) * PATH_LIMIT);
fprintf(stdout, "Please insert the full pathname of the audio file.\nPathname: ");
fgets(filePath, PATH_LIMIT, stdin);
CFURLRef audioFileURL = CFURLCreateFromFileSystemRepresentation(NULL, (Byte *)filePath, strlen(filePath),
false);
if(!audioFileURL) printf("Can't parse file path.\n");
result = AudioFileOpenURL(audioFileURL, kAudioFileReadPermission, 0, &userData->queueId);
if(result != noErr) {
printf("Unable to open AudioFile\n");
exit(1);
}
CFRelease(audioFileURL);
free(filePath);
}
P.S. note that queueId is an AudioFileId object and PATH_LIMIT is defined as 200
result, after the AudioFileOpenUrl's call has value 2003334207.