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

前端 未结 2 1435
旧巷少年郎
旧巷少年郎 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: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.

提交回复
热议问题