是否可以使用 AVAudioSessionCategoryPlayback 更改 AVPlayer 的音频路由?

Is it possible to change the audio route of an AVPlayer with AVAudioSessionCategoryPlayback?

我有一个 AVPlayer 可以播放流式音频或音频文件。 [AVAudioSession sharedInstance] 配置了 AVAudioSessionCategoryPlayback 类别。
它在前台和后台播放,一切正常。
我想添加这个 SO 问题中描述的功能How to play audio through built-in earpiece speaker 当应用程序不在后台时。
我已阅读上面的问题和说明的文档:

You can programmatically influence the audio output route. When using the AVAudioSessionCategoryPlayAndRecord category, audio normally goes to the receiver (the small speaker you hold to your ear when on a phone call). You can redirect audio to the speaker at the bottom of the phone by using the overrideOutputAudioPort:error: method.

所以我的问题是:我可以更改保持 AVAudioSessionCategoryPlayback 的 AVPlayer 的音频路由还是必须切换到 AVAudioSessionCategoryPlayAndRecord
将类别更改为 AVAudioSessionCategoryPlayAndRecord 是否有任何缺点?

您强烈需要使用 AVAudioSessionCategoryPlayAndRecord,因为通过 overrideOutputAudioPort 更改音频路由不适用于 AVAudioSessionCategoryPlayback(Apple 文档)

未发现 AVAudioSessionCategoryPlayAndRecordAVAudioSessionCategoryPlayback 之间存在任何显着差异。

AVAudioSessionCategoryPlayAndRecord 适用于同时播放和录制语音的 VOIP 场景。 在您的情况下,您不需要使用 AVAudioSessionCategoryPlayAndRecordAVAudioSessionCategoryPlayback 足以满足 AVPlayer。因为你只是在播放音频文件或流媒体。

谢谢