Tutorial :AudioFileWriteBytes returns error -50 randomly



Question:

I have the following code snippet:

    OSStatus status = AudioFileWriteBytes(self.audioFile, FALSE, self.startingByte, &ioNumBytes, theData);  

The status code randomly returns noErr and -50 on the iPhone simulator.

It then works if I re-run it.

Any pointer is appreciated why the above code behaves randomly.

Thanks in advance for your help.


Solution:1

I think I found my issue.

The original code with the problem:

// Start  OSStatus status = AudioOutputUnitStart(self.ioUnit);    // Record the audio samples and save it to a file  [self createFile];  

The new code that fixed the problem. Notice the "createFile" is called first before calling AudioOutputUnitStart

    // Record the audio samples and save it to a file  [self createFile];    // Start  // Once AudioOutputUnitStart is called, it will start calling callback method quickly. We need to call the above [self createFile] first.  OSStatus status = AudioOutputUnitStart(self.ioUnit);  

The AudioOutputUnitStart calls the callback method which will write audio samples to a file. Since the file has been created/opened before AudioOutputUnitStart, now the audio samples are written to the file without any error.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »