简体   繁体   English

如何使用 UIWebView 或 WKWebView 在后台连续播放音乐

[英]How can I play music successively in the background with UIWebView or WKWebView

The website implemented inside my app would play a series of mp3 files,it works well when the app is active,but when I press HOME button or lock the phone,it cannont play more than ONE song in the background,after that,app suspended.在我的应用程序中实现的网站会播放一系列 mp3 文件,当应用程序处于活动状态时效果很好,但是当我按 HOME 键或锁定手机时,它不能在后台播放多首歌曲,之后应用程序暂停. I've already tried to set different kind of AVAudioSession Category ,but of no use.我已经尝试过设置不同类型的AVAudioSession Category ,但没有用。

I assume you don't have audio background mode enabled.我假设您没有启用audio背景模式。 This is what Apple documentation says:这是苹果文档所说的:

When the UIBackgroundModes key contains the audio value, the system's media frameworks automatically prevent the corresponding app from being suspended when it moves to the background.当 UIBackgroundModes 键包含音频值时,系统的媒体框架会自动阻止相应的应用程序在移动到后台时被暂停。 As long as it is playing audio or video content or recording audio content, the app continues to run in the background.只要它正在播放音频或视频内容或录制音频内容,该应用程序就会继续在后台运行。 However, if recording or playback stops, the system suspends the app.但是,如果录制或播放停止,系统会暂停应用程序。

So it seems like you just need to enable audio background mode.所以看起来你只需要启用audio背景模式。 Here is Ray Wenderlich's tutorial on background modes这是Ray Wenderlich 关于背景模式的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM