mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Fix PiP close on Mac
This commit is contained in:
parent
16fb7087e3
commit
c0053cf837
@ -31,7 +31,9 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
|
|||||||
player.controls.objectWillChange.send()
|
player.controls.objectWillChange.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {}
|
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {
|
||||||
|
player.show()
|
||||||
|
}
|
||||||
|
|
||||||
func pictureInPictureController(
|
func pictureInPictureController(
|
||||||
_: AVPictureInPictureController,
|
_: AVPictureInPictureController,
|
||||||
|
@ -143,14 +143,12 @@ import SwiftUI
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct AppleAVPlayerView: NSViewRepresentable {
|
struct AppleAVPlayerView: NSViewRepresentable {
|
||||||
@State private var pictureInPictureDelegate = MacOSPiPDelegate()
|
|
||||||
|
|
||||||
func makeNSView(context _: Context) -> some NSView {
|
func makeNSView(context _: Context) -> some NSView {
|
||||||
let view = AVPlayerView()
|
let view = AVPlayerView()
|
||||||
view.player = PlayerModel.shared.avPlayerBackend.avPlayer
|
view.player = PlayerModel.shared.avPlayerBackend.avPlayer
|
||||||
view.showsFullScreenToggleButton = true
|
view.showsFullScreenToggleButton = true
|
||||||
view.allowsPictureInPicturePlayback = true
|
view.allowsPictureInPicturePlayback = true
|
||||||
view.pictureInPictureDelegate = pictureInPictureDelegate
|
view.pictureInPictureDelegate = MacOSPiPDelegate.shared
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ struct PlayerBackendView: View {
|
|||||||
{
|
{
|
||||||
AppleAVPlayerView()
|
AppleAVPlayerView()
|
||||||
} else if !avPlayerUsesSystemControls ||
|
} else if !avPlayerUsesSystemControls ||
|
||||||
|
player.playingInPictureInPicture ||
|
||||||
player.avPlayerBackend.isStartingPiP
|
player.avPlayerBackend.isStartingPiP
|
||||||
{
|
{
|
||||||
AppleAVPlayerLayerView()
|
AppleAVPlayerLayerView()
|
||||||
|
@ -2,6 +2,8 @@ import AVKit
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
|
final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
|
||||||
|
static let shared = MacOSPiPDelegate()
|
||||||
|
|
||||||
var playerModel: PlayerModel { .shared }
|
var playerModel: PlayerModel { .shared }
|
||||||
|
|
||||||
func playerViewShouldAutomaticallyDismissAtPicture(inPictureStart _: AVPlayerView) -> Bool {
|
func playerViewShouldAutomaticallyDismissAtPicture(inPictureStart _: AVPlayerView) -> Bool {
|
||||||
@ -16,19 +18,14 @@ final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func playerViewWillStopPicture(inPicture _: AVPlayerView) {
|
func playerViewWillStopPicture(inPicture _: AVPlayerView) {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
|
playerModel.show()
|
||||||
self?.playerModel.playingInPictureInPicture = false
|
playerModel.playingInPictureInPicture = false
|
||||||
self?.playerModel.show()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func playerView(
|
func playerView(
|
||||||
_: AVPlayerView,
|
_: AVPlayerView,
|
||||||
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
|
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
|
||||||
) {
|
) {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
|
|
||||||
self?.playerModel.show()
|
|
||||||
}
|
|
||||||
completionHandler(true)
|
completionHandler(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user