yattee/macOS/PictureInPictureDelegate.swift
2021-10-28 19:15:43 +02:00

29 lines
848 B
Swift

import AVKit
import Foundation
final class PictureInPictureDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
var playerModel: PlayerModel!
func playerViewShouldAutomaticallyDismissAtPicture(inPictureStart _: AVPlayerView) -> Bool {
false
}
func playerViewWillStartPicture(inPicture _: AVPlayerView) {
playerModel.playingInPictureInPicture = true
playerModel.presentingPlayer = false
}
func playerViewWillStopPicture(inPicture _: AVPlayerView) {
playerModel.playingInPictureInPicture = false
playerModel.presentPlayer()
}
func playerView(
_: AVPlayerView,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
) {
playerModel.presentingPlayer = true
completionHandler(true)
}
}