AudioFileOpen not opening with read/write permissions

I am trying to programmatically optimize AAC files (.m4a) that were created by software other than iTunes or afconvert using AudioFileOptimize().

However, when I attempt to do an AudioFileOpen with read/write permission and it gives me an error. I can only open with read permissions even if I manually set the POSIX permissions to 0666 (r/w for everyone.)

I'm using the AudioFileOpenUrl method described here and get back 'prm?' (kAudioFilePermissionsError).

Here is the code that is throwing the error:

#import <Cocoa/Cocoa.h>
#import <CoreFoundation/CoreFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import "CAXException.h"



int main(int argc, const char * argv[])
{

    int result = 0;

    try {

    //optimize the output file:
    AudioFileID outfile;

    NSURL *outputFileURL = [NSURL fileURLWithPath:@"/DIR/PATH TO.m4a"];

    OSStatus err = AudioFileOpenURL((__bridge CFURLRef)outputFileURL, kAudioFileReadWritePermission, 0, &outfile);
    XThrowIfError(err, "AudioFileOpenURL");

    err = AudioFileOptimize(outfile); //Optimize the file
    XThrowIfError(err, "AudioFileOptimize");

    err = AudioFileClose(outfile);
    XThrowIfError(err, "AudioFileClose");

    } catch (CAXException e) {
        char str[32];
        printf ("CAXException thrown from CoreAudioConverter.mm. : %s, %s\n", e.FormatError(str), e.mOperation);
        result = 1;
    } catch (...) {
        result = 1;
    }

    return result;
}

This outputs:

CAXException thrown from CoreAudioConverter.mm. : 'prm?', AudioFileOpenURL

If anyone can help, that would be AWESOME!

Side-note, has anyone done any work programmatically adding streaming hints to aac files?

Thanks!

Answers


AudioFile Services will not allow Write access to certain files:

There is however a limitation when working with MPEG-4 file types which include; .mp4 (kAudioFileMPEG4Type), .m4a (kAudioFileM4AType), .3g2 (kAudioFile3GP2Type) and .3gp (kAudioFile3GPType).

AudioFile does not currently support writing to existing files of these types.

See: http://developer.apple.com/library/mac/#qa/qa1676/_index.html


Need Your Help

Android Search Framework, Custom Search Suggestions

java android android-contentprovider android-searchmanager

I am developing an application that implements a search provider. The behaviour that I am trying to accomplish is if an item is not found in the database, I want an item to show up in the search

Define number of cycles - Benchmark.js

javascript benchmark.js

I am trying to execute a sample performance benchmark using Benchmark.js.