如何确定 iOS 中的音频会话是否处于活动状态
我在 iOS 应用程序中使用 AudioSessionSetActive
(true) 和 AudioSessionSetActive
(false) 将 AudioSession
设置为 true 或 false。 在任何时候,我都想知道会话是否处于活动状态。有办法做到这一点吗?
I'm using AudioSessionSetActive
(true) and AudioSessionSetActive
(false) for setting the AudioSession
to true or false in my iOS app.
At any point, I want to find out whether the session is active or not. Is there a way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用此 api 来查明音频会话在 iOS 中是否处于活动状态。
You can use this api to find out if audio session is active in iOS.
刚刚遇到同样的事情!没有用于查询会话是否处于活动状态的 AudioSessionProperty 键。我相信这是另一种“一劳永逸”的交易,苹果认为应用程序应该以某种方式运行。例如。大多数应用程序不需要知道状态,他们应该在需要音频时设置它,并在播放完音频后无条件终止它。当然这只适用于90%的人。抱歉,这不是最好的答案,我只是报告我的怀疑。也许其他人有更好的主意?
Just ran into the same thing! There is no AudioSessionProperty key for querying whether or not the session is active. I believe this is another one of those set it and forget it deals where Apple believes apps should behave a certain way. Eg. most apps shouldn't need to know the state they should just set it as they need audio and kill it unconditionally as they are done playing audio. Of course this only works for the 90%. Apologies as this is not the best answer, I'm only reporting my suspicions. Maybe others have a better idea?
您可以在启动应用程序时检查
otherAudioPlaying
属性,检查是否有其他应用程序启动时正在播放音频。对于内部跟踪,也许您可以在执行
AudioSessionSetActive(BOOL setActive)
调用时使用布尔值。尽管使用 BOOL 听起来并不是一个很好的方法。鉴于我目前的知识,我找不到任何其他方法来确定 AudioSession 是否处于活动状态。You can check if any audio is playing as it was launched by another app by inspecting the
otherAudioPlaying
property when you launch the app.For internal tracking perhaps you could use a boolean when you do the
AudioSessionSetActive(BOOL setActive)
call. Though use of BOOL does not sound as a wonderful approach. Given my current knowledge I couldnt find any other way of determining if the AudioSession is active or not.