Skip to content

Commit 2ff17bd

Browse files
committed
handle removed presented view controller better
1 parent 15ce855 commit 2ff17bd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

bk2ch15p659SimplestAVKit/SimplestAVKit/ViewController.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class ViewController: UIViewController {
2323
}
2424

2525

26-
26+
var pic = false // is picture in picture going on?
2727
let which = 1 // 1 is present, 2 is push, but they no longer talk about that
2828

2929
@IBAction func doPresent(_ sender: Any) {
30+
if self.pic { return } // don't do this in the middle of picture in picture
3031
switch which {
3132
case 1:
3233
let av = AVPlayerViewController()
@@ -99,11 +100,18 @@ extension ViewController : AVPlayerViewControllerDelegate {
99100

100101

101102
func playerViewController(_ pvc: AVPlayerViewController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler ch: @escaping (Bool) -> Void) {
102-
self.present(pvc, animated:true) {
103+
self.present(pvc, animated:true) {
103104
ch(true)
104105
}
105106
}
106107

108+
func playerViewControllerDidStartPictureInPicture(_ playerViewController: AVPlayerViewController) {
109+
self.pic = true
110+
}
111+
112+
func playerViewControllerDidStopPictureInPicture(_ playerViewController: AVPlayerViewController) {
113+
self.pic = false
114+
}
107115

108116
}
109117

0 commit comments

Comments
 (0)