fix(tvos): stabilize remote input and player build

This commit is contained in:
edde746
2026-05-06 08:47:13 +02:00
parent 4700cc5bd4
commit de547884f8
4 changed files with 151 additions and 11 deletions
+17 -6
View File
@@ -45,7 +45,9 @@ class MpvPlayerCore: MpvPlayerCoreBase {
}
setupNotifications()
ExternalDisplayManager.shared.attach(core: self)
#if os(iOS)
ExternalDisplayManager.shared.attach(core: self)
#endif
isInitialized = true
print("[MpvPlayerCore] Initialized successfully with MPV")
@@ -128,10 +130,7 @@ class MpvPlayerCore: MpvPlayerCoreBase {
private func refreshExternalDisplayAttachment() {
guard let containerView else { return }
let externalSuperview =
isVisible && !isPipActive && !isPipStarting
? ExternalDisplayManager.shared.videoSuperview
: nil
let externalSuperview = externalVideoSuperview
if let externalSuperview {
moveContainerView(to: externalSuperview)
@@ -147,6 +146,16 @@ class MpvPlayerCore: MpvPlayerCoreBase {
updateFrame()
}
private var externalVideoSuperview: UIView? {
#if os(iOS)
isVisible && !isPipActive && !isPipStarting
? ExternalDisplayManager.shared.videoSuperview
: nil
#else
nil
#endif
}
private func moveContainerView(to superview: UIView) {
guard let containerView else { return }
@@ -207,7 +216,9 @@ class MpvPlayerCore: MpvPlayerCoreBase {
func dispose() {
NotificationCenter.default.removeObserver(self)
ExternalDisplayManager.shared.detach(core: self)
#if os(iOS)
ExternalDisplayManager.shared.detach(core: self)
#endif
disposeSharedState(destroySynchronously: false)
metalLayer?.removeFromSuperlayer()
+24 -2
View File
@@ -123,7 +123,11 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
}
private var isSceneActive: Bool {
ExternalDisplayManager.hasActiveApplicationScene
#if os(iOS)
ExternalDisplayManager.hasActiveApplicationScene
#else
UIApplication.shared.connectedScenes.contains { $0.activationState == .foregroundActive }
#endif
}
private func restoreInlinePlayerAfterPip() {
@@ -362,7 +366,25 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
// MARK: - Helpers
private func findKeyWindow() -> UIWindow? {
ExternalDisplayManager.mainApplicationWindow()
#if os(iOS)
return ExternalDisplayManager.mainApplicationWindow()
#else
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
for scene in scenes {
if let window = scene.windows.first(where: { $0.isKeyWindow }) {
return window
}
}
for scene in scenes {
if let window = scene.windows.first(where: { !$0.isHidden }) {
return window
}
}
return scenes.first?.windows.first
#endif
}
}