快速获取设备音量而不中断当前播放
我想获取设备当前的输出音量。我已经搜索了很长一段时间,我知道有关于这个主题的各种线索,但我真的找不到一种方法来在阅读卷时保持播放。 我发现的最多的事情是这样的:
let audioSession = AVAudioSession.sharedInstance()
var volume: Float?
do {
try audioSession.setActive(true)
volume = audioSession.outputVolume
} catch {
print("Error Setting Up Audio Session")
}
但是通过将 active
参数设置为 true,似乎所有其他输出都被取消了。
有没有一种方法可以在没有所描述的副作用的情况下获得音量?
I want to get the current output volume of a device. I have been searching around for a very long time and I know there are various threads about this topic but I really could not find a way to keep the playback going when reading the volume.
The most things I found were something like this:
let audioSession = AVAudioSession.sharedInstance()
var volume: Float?
do {
try audioSession.setActive(true)
volume = audioSession.outputVolume
} catch {
print("Error Setting Up Audio Session")
}
But by setting the active
parameter to true it seems that every other output is just canceled.
Is there a way to get the volume without the described side effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我通过将播放选项设置为 mixWithOthers 解决了这个问题。我认为这意味着它接受同时播放。这是在不中断当前播放的情况下获取音量的函数:
So I solved the problem by setting the playback option to be
mixWithOthers
. I assume that means, that it accepts simultaneously playback. Here is the function to get the volume without disrupting the current playback: