Reputation: 2867
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 -
Created a new audio queue for recording audio data.
status = AudioQueueNewInput(&_state.dataFormat,
AudioInputCallback,
&_state,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes,
0,
&_state.queue);
Sets an audio queue property value.
status = AudioQueueSetProperty(_state.queue,kAudioQueueProperty_EnableLevelMetering,&on,sizeof(on));
an audio queue to allocate a buffer.
status = AudioQueueAllocateBuffer(_state.queue, buffer_size, &_state.buffers[i]);
Assigns a buffer to an audio queue for recording or playback.
status = AudioQueueEnqueueBuffer (_state.queue, _state.buffers[i], 0, NULL);
Added a listener callback for a property.
status = AudioQueueAddPropertyListener(_state.queue,
kAudioQueueProperty_IsRunning,
recordingRunningChangedCallback,
&_state);
Begins playing or recording audio.
status = AudioQueueStart(_state.queue, NULL);
And last steps returns error with
error code -50
Upvotes: 4
Views: 2944
Reputation: 373
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
Upvotes: 0
Reputation: 870
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);
}
Upvotes: 1
Reputation: 22946
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!
Upvotes: 0