gpt4 book ai didi

ios - 什么时候使用 AVAudioSession.setActive?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:25:02 52 4
gpt4 key购买 nike

我的理解是,您的应用中只能有 1 个 AVAudioSession(因为它是单例,因此您总是收到相同的实例)。

那么,setActive() 函数的作用是什么?因为我只能有一个 session ,所以我没有看到该功能的合适用例。

AVAudioSession 文档:https://developer.apple.com/documentation/avfoundation/avaudiosession

最佳答案

来自 Apple doc:

通过setActive,您的应用程序要求系统使用音频。例如,您可以在音乐应用程序正在播放时发出请求,系统会根据优先级状态中断它以播放您的音频。

Activating and Deactivating Your Audio Session

Although the AVFoundation playback and recording classes automatically activate your audio session, manually activating it gives you an opportunity to test whether activation succeeded. However, if your app has a play/pause UI element, write your code so that the user must press Play before the session is activated. Likewise, when changing your audio session’s active/inactive state, check to ensure that the call is successful. Write your code to gracefully handle the system’s refusal to activate your session.

The system deactivates your audio session for a Clock or Calendar alarm or an incoming phone call. When the user dismisses the alarm, or chooses to ignore a phone call, the system allows your session to become active again.

关于ios - 什么时候使用 AVAudioSession.setActive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48053785/

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