-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Issue about subclassing AVPlayerViewController #89
Comments
Try with simply putting AVPlayerViewController as a child controller of CommonPlayerViewController (fix/avplayerVC-child 541d204). But the directional key of the remote is not working or not forwarded to AVPlayerViewController. May need more research with the tvOS event chain. |
another propose is make CommonPlayerViewController become a simple util to present avplayerVC only. move all danmuView, maskView and related logic to the overlayContentView of the AVPlayerVC. |
If we just make CommonPlayerViewController a simple class or a subclass of NSObject and add a property var player: AVPlayerViewController. How to prevent the CommonPlayerViewController deinit immediately after present the AVPlayerViewController. There is not a view hierarchy to keep it. Or just do some hacky work like the overlayContentView holding the CommonPlayerViewController? |
Take VideoDetailViewController/VideoPlayerViewController as an example: In The original code: func present(from vc: UIViewController, direatlyEnterVideo: Bool = Settings.direatlyEnterVideo) {
if !direatlyEnterVideo {
vc.present(self, animated: true)
} else {
vc.present(self, animated: false) { [weak self] in
guard let self else { return }
let player = VideoPlayerViewController(playInfo: PlayInfo(aid: self.aid, cid: self.cid, epid: self.epid, isBangumi: self.isBangumi))
self.present(player, animated: true)
}
}
} The new code can be written as follow
unowned var player: AVPlayerViewController Also we somehow make
func present(from vc: UIViewController, direatlyEnterVideo: Bool = Settings.direatlyEnterVideo) {
if !direatlyEnterVideo {
vc.present(self, animated: true)
} else {
vc.present(self, animated: false) { [weak self] in
guard let self else { return }
let controller = VideoPlayerViewController(playInfo: PlayInfo(aid: self.aid, cid: self.cid, epid: self.epid, isBangumi: self.isBangumi))
self.present(controller.player, animated: true)
}
}
} |
yep, I am thinking is there is a simply elegant way to make |
After override the |
Typo here? I guess you mean putting AVPlayerViewController as a child controller of CommonPlayerViewController |
you are right, now putting AVPlayerViewController as a child controller of CommonPlayerViewController works fine |
The current VC inheritance chain is VideoPlayerViewController -> CommonPlayerViewController -> AVPlayerViewController.
But Apple's AVKit documentation states that "The framework doesn’t support subclassing AVPlayerViewController."
Some issue I met before(setting
AVPlaybackSpeed
and not working) may also be related to our usage of inheritance for AVPlayerViewController.But anyway using subclass of
AVPlayerViewController
has some risk that it may not work in future OS update. I'd like to suggest we makeCommonPlayerViewController
a simple class or a subclass of NSObject and add a propertyvar player: AVPlayerViewController
to refactor our codebase.The text was updated successfully, but these errors were encountered: