1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-12 21:30:32 +05:30

Fix PiP close on Mac

This commit is contained in:
Arkadiusz Fal 2023-05-22 22:48:11 +02:00
parent 16fb7087e3
commit c0053cf837
4 changed files with 9 additions and 11 deletions

View File

@ -31,7 +31,9 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
player.controls.objectWillChange.send()
}
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {}
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {
player.show()
}
func pictureInPictureController(
_: AVPictureInPictureController,

View File

@ -143,14 +143,12 @@ import SwiftUI
}
#else
struct AppleAVPlayerView: NSViewRepresentable {
@State private var pictureInPictureDelegate = MacOSPiPDelegate()
func makeNSView(context _: Context) -> some NSView {
let view = AVPlayerView()
view.player = PlayerModel.shared.avPlayerBackend.avPlayer
view.showsFullScreenToggleButton = true
view.allowsPictureInPicturePlayback = true
view.pictureInPictureDelegate = pictureInPictureDelegate
view.pictureInPictureDelegate = MacOSPiPDelegate.shared
return view
}

View File

@ -28,6 +28,7 @@ struct PlayerBackendView: View {
{
AppleAVPlayerView()
} else if !avPlayerUsesSystemControls ||
player.playingInPictureInPicture ||
player.avPlayerBackend.isStartingPiP
{
AppleAVPlayerLayerView()

View File

@ -2,6 +2,8 @@ import AVKit
import Foundation
final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
static let shared = MacOSPiPDelegate()
var playerModel: PlayerModel { .shared }
func playerViewShouldAutomaticallyDismissAtPicture(inPictureStart _: AVPlayerView) -> Bool {
@ -16,19 +18,14 @@ final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
}
func playerViewWillStopPicture(inPicture _: AVPlayerView) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.playerModel.playingInPictureInPicture = false
self?.playerModel.show()
}
playerModel.show()
playerModel.playingInPictureInPicture = false
}
func playerView(
_: AVPlayerView,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.playerModel.show()
}
completionHandler(true)
}
}