Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么AVAudioPlayer在应用程序来自后台模式后会自动继续播放?_Iphone_Background_Avaudioplayer_Avaudiosession - Fatal编程技术网

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

Iphone 为什么AVAudioPlayer在应用程序来自后台模式后会自动继续播放?,iphone,background,avaudioplayer,avaudiosession,Iphone,Background,Avaudioplayer,Avaudiosession,为什么AVAudioPlayer在应用程序从后台模式启动后继续播放,即使在应用程序进入后台之前播放器已经暂停 一般来说,我想知道为什么AVAudioPlayer在应用程序来自后台后会自动继续播放(因为当应用程序进入后台时,我不能像其他代理一样捕捉到beginInterruption) AVAudioPlayer和AVAudioSession的)。 ps:对不起,我的英语:)当你在后台推应用程序时,应用程序将处于休眠状态,即不再处于活动状态。这就是您无法捕获beginInterruption的原因

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

一般来说,我想知道为什么AVAudioPlayer在应用程序来自后台后会自动继续播放(因为当应用程序进入后台时,我不能像其他代理一样捕捉到beginInterruption) AVAudioPlayer和AVAudioSession的)。
ps:对不起,我的英语:)

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

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

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


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

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

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