AVAudioSessionManager availableInputs “Unknown selected data source for port iPhone Microphone”

前端 未结 2 1434
旧巷少年郎
旧巷少年郎 2021-02-18 13:00

I\'ve noticed this error in my console log for a while. Though it does not affect the execution of my application, I find it really annoying. Thus, I started to trace where this

相关标签:
2条回答
  • 2021-02-18 13:56

    This problem seems not just happen to me... I will just share my understanding here..

    My situation is.. I'm using pjsip library, which has a lower level control of audio resources. I've noticed that, the sound device has been closed before I call [[AVAudioSession sharedInstance] availableInputs];

    Thus, (I guess) AVAudioSession, as a higher level control, couldn't find corresponding audio data source for its input - as the error indicated...

    To further investigate the problem, you'd better check somewhere in your code that modify the audio source.. and make sure the audio source is activated before you call AVAudioSession

    I can only go this far for now... Deeper understanding and better explanation of audio control is always appreciated!!

    0 讨论(0)
  • 2021-02-18 13:57

    Regarding the error in your console, I can also confirm that I sometimes receive this message when using my iPhone 5S, but I've never seen it on my 4S. It could just be some core audio dump, but it doesn't seem to affect actual performance (at least for me).

    Regarding the available inputs, what your actually printing out is the available input ports and their descriptions. This bit is more confusing and I don't understand why the selectedDataSource field is null for each one.

    I will say that the iPhone is definitely defaulting to one of those sources (probably the Built-in Mic) regardless of what the selectedDataSource is saying.

    Now if you wanted to explicitly select one of the port descriptions you could do something like this:

    NSArray *availableInputs = [[AVAudioSession sharedInstance] availableInputs];
    AVAudioSessionPortDescription *port = [availableInputs objectAtIndex:0];  //built in mic for your case
    NSError *portErr = nil;
    [[AVAudioSession sharedInstance] setPreferredInput:port error:&portErr];
    

    and I would check portErr afterwards to make sure there's no error in setting the preferredInput.

    Its worth noting that you can also cycle through the available dataSources for a particular Port Description as well and select one using

    [port setPreferredDataSource:source error:&sourceErr];
    

    then follow that with:

    [[AVAudioSession sharedInstance] setPreferredInput:port error:&portErr];
    

    These are some handy iOS7 only features that take advantage of hardware with multiple built-in mice.

    0 讨论(0)
提交回复
热议问题