什么时候使用 AVAudioSession.setActive?
When to use AVAudioSession.setActive?
我的理解是,您的应用程序中只能有 1 个 AVAudioSession(因为它是单例,因此您总是收到相同的实例)。
那么,setActive()函数的目的是什么?因为我只能有一个会话,所以我没有看到该功能的正确用例。
AVAudioSession 文档:https://developer.apple.com/documentation/avfoundation/avaudiosession
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.
我的理解是,您的应用程序中只能有 1 个 AVAudioSession(因为它是单例,因此您总是收到相同的实例)。
那么,setActive()函数的目的是什么?因为我只能有一个会话,所以我没有看到该功能的正确用例。
AVAudioSession 文档:https://developer.apple.com/documentation/avfoundation/avaudiosession
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.