使用setVolume褪色时,avaudioplayer卷会跳跃(_:fadeduration :)

发布于 2025-01-23 10:56:09 字数 790 浏览 4 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文