Can't cast video via google cast correctly in ios app

爷,独闯天下 提交于 2019-12-05 11:22:10

On possible solution could be due to:

sessionManager?.add(self)

You add the delegate but at no point do you clear it. As a result, the VideoVC is never destroyed due to the retained reference from the session manager. When you reopen the VideoVC the session manager is still also accessing the delegate from the first time you loaded it.

Because of this, when the following is called:

func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKSession) {

This is being called in your first instance of VideoVC which now has the wrong file information.

You can monitor this by putting a print(self) into the above method and look at the memory pointer value. Check that it also matches the same memory pointer value that is called in viewDidLoad

Update

To better manage the delegate change the following method: viewDidDisappear()

override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    player.replaceCurrentItem(with: nil)

    //this stops the session manager sending callbacks to your VideoVC
    sessionManager.remove(self)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!