gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:33:44 26 4
gpt4 key购买 nike

我有一个 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.

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

最佳答案

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

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

关于ios - 是否可以使用 AVAudioSessionCategoryPlayback 更改 AVPlayer 的音频路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35195508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com