当 iPhone 锁定/解锁并且应用程序处于后台时如何恢复音频
情况是这样的:我使用 Audio Streamer 库 制作了一个应用程序,该应用程序从远程读取音频文件服务器,但只有这样做时我才会发现问题:
- 启动应用程序
- 启动播客(音频流)
- 暂停它
- 将应用程序放在后台(主页按钮)
- 锁定手机
- 解锁它
- 重新激活应用程序
然后,我的流将被停止。我试图达到暂停状态,但无法完成。
仅当我将应用程序置于后台时才会发生这种情况,如果没有,并且我锁定/解锁 iPhone,一切都会恢复正常。如果我暂停流,然后将应用程序置于后台(主页按钮),然后应用程序从后台状态退出,则一切正常。
因此,只有发生以下两种情况时才会出现此问题:应用程序发送到后台+锁定/解锁iPhone
This is the case: I made an app using the Audio Streamer library that reads an audio file from a remote server, but I find a problem only if I do this:
- Launch the app
- Start a Podcast (audio stream)
- Pause it
- Put the app on the background (home button)
- Lock the phone
- Unlock it
- Reactivate the app
And only then, my stream will be stopped. I am attempting to reach the paused state, but could not get it done.
This happens only if I put the app in background, if not and I lock/unlock the iPhone, everything is alright again. If I pause the stream then put the app into background (Home button) and then the app is resigned from background-state, everything is OK.
So, this problem only occurs if these two things happen: App sent to background + Lock/unlock the iphone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它在幕后使用 AVAudioPlayer 吗?如果是这样,您需要处理 AVAudioPlayerDelegate 协议:
和
.. 方法。本质上使用第一个来存储 AVAudioPlayer 由于中断而停止的事实,并使用第二个来重新启动它。繁琐,但不幸的是必要的。
这是一个链接 https://developer.apple.com/documentation/avfoundation/avaudioplayerdelegate
does it use AVAudioPlayer under the hood? If so you need to handle the AVAudioPlayerDelegate protocols:
and
.. methods. Essentially use the first to store the fact that the AVAudioPlayer was stopped due to an interruption, and the second to start it off again. Fiddly, but unfortunately neccessary.
Here's a link https://developer.apple.com/documentation/avfoundation/avaudioplayerdelegate