0
我有一个应用程序从互联网下载视频,并通过我的应用程序播放我需要在后台播放视频时,用户退出从应用程序它仍然工作我该如何执行此操作任务我尝试在现场堆栈溢出一些问题,但不能修复我的问题,我添加以下代码,使其论文,也没有工作问题与播放视频在背景使用SWIFT 3
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.beginReceivingRemoteControlEvents()
self.becomeFirstResponder()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.endReceivingRemoteControlEvents()
self.resignFirstResponder()
}
override func remoteControlReceived(with event: UIEvent?) {
if event?.subtype == UIEventSubtype.remoteControlPlay {
print("Play")
}
}
,也是我在AppDelegate的
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let getAvAudioSession = AVAudioSession.sharedInstance()
do {
try getAvAudioSession.setActive(true)
try getAvAudioSession.setCategory(AVAudioSessionCategoryPlayback)
}catch{
print(error)
}
return true
}
添加以下代码
而且我还在应用程序中启用背景模式从capabil伊蒂埃斯也没有工作
请能解决这个问题我
非常感谢
这是不正确的:''setupNowPlayingInfoCenter()'应该启动到'viewDidLoad'方法,你不应该每次开始播放时都调用它,或者关闭MPRemoteCommandCenter –