我使用YouTube iOS帮助程序库在WKWebView
内播放视频,我希望即使按下HOME键或锁定键,音频也会继续播放。
功能选项卡如下所示:
我还在import AVFoundation
AppDelegate
和func applicationDidBecomeActive(_ application: UIApplication)
内部我有这段代码:
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
// Handle setCategory failure
print(error)
}
}
当应用程序进入后台音频停止时,我甚至无法从控制中心恢复它。
答案 0 :(得分:0)
对于那些正在寻找类似解决方案的人,想告诉他们,播放YouTube音频而不显示视频违反了the terms of services of YouTube,因此您的应用将被App Store拒绝。