0

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.

pino
  • 25
  • 8
  • What error is `kAudioFileUnspecifiedError = 'wht?'` which doesn't help much. Try `CFShow()`ing your `audioFileURL`. – Rhythmic Fistman Mar 07 '17 at 00:46
  • Thanks for your reply, but luckily I've just found the error. With fgets i get, togheter with the string, also the '\n' character. Substituting with '\0' worked. – pino Mar 07 '17 at 16:33

0 Answers0