为什么 AVAudioPlayer 在应用程序退出后台模式后自动继续播放?

发布于 2024-10-15 12:11:06 字数 204 浏览 7 评论 0原文

为什么 AVAudioPlayer 在应用程序退出后台模式后继续播放,即使播放器在应用程序进入后台之前已暂停?

共同点我想知道为什么 AVAudioPlayer 在应用程序来自后台后自动继续播放(因为当应用程序进入后台时 - 我无法像其他代表一样捕获 beginInterruption AVAudioPlayer 和 AVAudioSession)。 PS:对不起我的英语:)

Why do AVAudioPlayer continue playing after applcation comes from background mode, even if the player had been paused before app went to background?

In common I wonder why AVAudioPlayer automatically continue playing after application comes from background (cause when app going to background - i can't catch as beginInterruption as other delegates
of AVAudioPlayer and AVAudioSession).
ps:sorry for my english:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁〃客ぐ 2024-10-22 12:11:06

当您将应用程序推入后台时,该应用程序将进入休眠状态,即不再处于活动状态。这就是您无法捕获 beginInterruption 的原因。当应用程序进入前台时,应用程序再次激活,这就是 AVAudioPlayer 再次开始播放的原因..我希望这有帮助

when you push the app in background the app becomes dormant i.e. it is no longer active. This is the reason that you are unable to catch beginInterruption. When the app is brought in foreground the app becomes active again, this is why AVAudioPlayer starts playing again..I hope this helps

终遇你 2024-10-22 12:11:06

今天我花了相当多的时间试图弄清楚同样的事情。

每当我的应用程序进入后台模式时,音频都会在 UIApplicationDidEnterBackgroundNotification 之后自动暂停,并在我收到 UIApplicationWillEnterForegroundNoticiation 之前继续播放。即使当我收到后台通知时暂停它。

在此处输入图像描述

当我启用 UIBackgroundMode 音频时,我能够暂停我的 AudioQueue(或 AVAudioPlayer,如果您使用它)当应用程序进入后台时我自己。这导致我的 UI 显示音频播放器已暂停,并使我能够完全控制应用程序状态之间的音频播放。

I spend quite some hours today trying to figure out the exact same thing.

Whenever my application entered background mode, the audio would automatically pause itself after a UIApplicationDidEnterBackgroundNotification and continue playing before I got a UIApplicationWillEnterForegroundNoticiation. Even when I paused it when I received the background notification.

enter image description here

When I enabled the UIBackgroundMode audio, I was able to pause my AudioQueue (or AVAudioPlayer if you use that) myself when the application entered background. This resulted in my UI showing that the audio player was paused and enabled me to get full control over audio playback in between application states.

嘦怹 2024-10-22 12:11:06

到目前为止,我为 iOS 13 SDK 提出的修复方案(不确定这是否相关,但对我来说,从 iOS 12 SDK 迁移到 13 后,这个错误就开始了),这看起来很奇怪:

// duplicate pausing the player when app resigns active
self.audioPlayer.pause()
self.audioPlayer.pause()

So far the fix I've come up with for iOS 13 SDK (not sure if this is relevant but the bug for me has started after migration from iOS 12 SDK to 13) is this as strange as it looks:

// duplicate pausing the player when app resigns active
self.audioPlayer.pause()
self.audioPlayer.pause()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文