mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Automatically dismiss player when playback finished on tvOS
This commit is contained in:
parent
8d5a191779
commit
c1d9e02475
@ -43,6 +43,9 @@ final class PlayerViewController: UIViewController {
|
||||
|
||||
#if os(tvOS)
|
||||
present(playerViewController, animated: false)
|
||||
|
||||
addItemDidPlayToEndTimeObserver()
|
||||
|
||||
#else
|
||||
embedViewController()
|
||||
#endif
|
||||
@ -52,7 +55,22 @@ final class PlayerViewController: UIViewController {
|
||||
playerLoaded = true
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
#if os(tvOS)
|
||||
func addItemDidPlayToEndTimeObserver() {
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(itemDidPlayToEndTime),
|
||||
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
||||
object: nil
|
||||
)
|
||||
}
|
||||
|
||||
@objc func itemDidPlayToEndTime() {
|
||||
playerViewController.dismiss(animated: true) {
|
||||
self.dismiss(animated: false)
|
||||
}
|
||||
}
|
||||
#else
|
||||
func embedViewController() {
|
||||
playerViewController.exitsFullScreenWhenPlaybackEnds = true
|
||||
playerViewController.view.frame = view.bounds
|
||||
|
Loading…
Reference in New Issue
Block a user