4

I have an audio app, and when AVAudioSessionRouteChangeNotification comes on, the app configures AV and tests for headphone use and such.

However, Siri activates the AVAudioSessionRouteChangeNotification, but because of the AV configuration, Siri isn't able to be used by the user (the microphone doesn't work for her, it seems.)

Is there a way to find out if Siri is the thing causing the AVAudioSessionRouteChangeNotification, so that I don't call the method to configure AV if it's Siri and thus let the user use Siri?

4

2 回答 2

2

没错,耳机插入/拔出和 Siri 激活都会触发AVAudioSessionRouteChangeNotification,但是,请注意AVAudioSessionRouteChangeReasonKey与通知相关联

插入耳机时,原因是AVAudioSessionRouteChangeReasonNewDeviceAvailable

当耳机被拔出时,原因是AVAudioSessionRouteChangeReasonOldDeviceUnavailable

当 Siri 被激活时,原因是AVAudioSessionRouteChangeReasonCategoryChange

于 2015-09-28T07:15:22.930 回答
0

如果您想检查 Siri 的开始或结束,请在 AVAudioSessionRouteChangeNotification 事件中使用以下代码:

AVAudioSessionRouteChangeReason routeChangeReason = [note.userInfo[AVAudioSessionRouteChangeReasonKey] integerValue];
AVAudioSessionRouteDescription* description = note.userInfo[AVAudioSessionRouteChangePreviousRouteKey];

BOOL isSiriStart = (routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange && description.inputs == nil);
BOOL isSiriFinish = (routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange && description.inputs != nil);
于 2015-09-28T07:58:41.577 回答