4

Start audio recording giving error sometimes and below method returns error

Error Domain=NSOSStatusErrorDomain Code=-50 "(null)" UserInfo= status = AudioQueueStart(_state.queue, NULL);

Followed below steps for recording audo -

  1. Created a new audio queue for recording audio data.

    status = AudioQueueNewInput(&_state.dataFormat, AudioInputCallback, &_state, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &_state.queue);

  2. Sets an audio queue property value.

    status = AudioQueueSetProperty(_state.queue,kAudioQueueProperty_EnableLevelMetering,&on,sizeof(on));

  3. an audio queue to allocate a buffer.

    status = AudioQueueAllocateBuffer(_state.queue, buffer_size, &_state.buffers[i]);

  4. Assigns a buffer to an audio queue for recording or playback.

    status = AudioQueueEnqueueBuffer (_state.queue, _state.buffers[i], 0, NULL);

  5. Added a listener callback for a property.

    status = AudioQueueAddPropertyListener(_state.queue, kAudioQueueProperty_IsRunning, recordingRunningChangedCallback, &_state);

  6. Begins playing or recording audio.

    status = AudioQueueStart(_state.queue, NULL);

And last steps returns error with

error code -50

Ganesh Manickam
  • 2,113
  • 3
  • 20
  • 28
Sudhakar Tharigoppula
  • 2,857
  • 3
  • 16
  • 17

3 Answers3

1

I've just had the same issue. For whatever reason calling AudioQueueStart twice did the trick for me:

status = AudioQueueStart(_state.queue, NULL);
if (status == -50) {
    status = AudioQueueStart(_state.queue, NULL);
}
user2378197
  • 760
  • 7
  • 11
0

As can be found here, this is AVAudioSessionErrorCodeBadParam.

So apparently one of the parameters you specify is invalid or a parameter is missing.

Does this help perhaps?

As setting up audio in iOS is rather intricate, I advice you to start from working sample code, or to follow a decent tutorial. From own experience I can tell that it's easy to miss something and get errors like this.

Good luck!

meaning-matters
  • 21,929
  • 10
  • 82
  • 142
0

I was getting this error because my AVAudioSession was not configured the right way.

If you only have an output queue, you need to configure your AVAudioSession with the AVAudioSessionCategoryPlayback category. Here is some code:

AVAudioSession *session = [AVAudioSession sharedInstance];
NSString *category = AVAudioSessionCategoryPlayback;
NSString *mode = AVAudioSessionModeDefault;
NSUInteger options = AVAudioSessionCategoryOptionMixWithOthers;
NSError *err = nil;
[session setCategory:category mode:mode options:options error:&err];

If you want output and input at the same time you can do the same with AVAudioSessionCategoryPlayAndRecord

Tom
  • 373
  • 3
  • 13