使用setVolume褪色时,avaudioplayer卷会跳跃(_:fadeduration :)
我有一个avaudioplayer
实例<代码> player 。当我按以下方式设置卷时,它可以按预期工作:卷从1开始,逐渐淡入0
player.volume = 1
player.setVolume(0, fadeDuration: 3)
。 当我运行此功能时,
player.volume = 0
player.setVolume(1, fadeDuration: 3)
音量立即跳到第1卷,而不会淡出任何淡出。这对我来说似乎是一个错误,因为该行为与一组值一起起作用,而不是另一组值。
我确实找到了解决方法在这里将卷淡入淡出的dispatchqueue
调用。
player.volume = 0
DispatchQueue.main.async {
self.audioPlayer?.setVolume(1, fadeDuration: 3)
}
这有效。但是我不明白为什么您需要一个dispatchqueue
调用以使其以一种方式工作,而不是另一种方式。谁能为此阐明吗?我想知道这是否是一个实际的错误,或者我只是在做错事或不正确理解某些事情。
I have an AVAudioPlayer
instance called player
. When I set the volume as follows, it works as expected: the volume begins at 1 and gradually fades to 0.
player.volume = 1
player.setVolume(0, fadeDuration: 3)
But there is a problem when I try to go the other way, as follows, starting at volume 0 and fading in to 1.
player.volume = 0
player.setVolume(1, fadeDuration: 3)
When I run this, the volume immediately jumps to volume 1 without any fade. This seems like a bug to me, because the behavior works with one set of values but not the other set of values.
I did find a workaround here, which wraps the volume fade in a DispatchQueue
call.
player.volume = 0
DispatchQueue.main.async {
self.audioPlayer?.setVolume(1, fadeDuration: 3)
}
This works. But I don't understand why you need a DispatchQueue
call to make it work one way, but not the other way. Can anyone shed some light on this? I'm wondering if this is an actual bug, or maybe I'm just doing something wrong or not understanding something correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论