为什么 AVAudioPlayer 在应用程序退出后台模式后自动继续播放?
为什么 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您将应用程序推入后台时,该应用程序将进入休眠状态,即不再处于活动状态。这就是您无法捕获 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
今天我花了相当多的时间试图弄清楚同样的事情。
每当我的应用程序进入后台模式时,音频都会在 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.
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.
到目前为止,我为 iOS 13 SDK 提出的修复方案(不确定这是否相关,但对我来说,从 iOS 12 SDK 迁移到 13 后,这个错误就开始了),这看起来很奇怪:
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: