Fixes for MPV in macOS

This commit is contained in:
Arkadiusz Fal
2022-02-27 21:31:17 +01:00
parent d32b38c352
commit 79118ff7e2
54 changed files with 695 additions and 249 deletions

View File

@@ -1,7 +1,7 @@
import Defaults
import SwiftUI
struct AVPlayerView: UIViewControllerRepresentable {
struct AppleAVPlayerView: UIViewControllerRepresentable {
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player

View File

@@ -8,7 +8,9 @@ struct PlayerControls: View {
@EnvironmentObject<PlayerControlsModel> private var model
@Environment(\.verticalSizeClass) private var verticalSizeClass
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
#endif
init(player: PlayerModel) {
self.player = player
@@ -84,7 +86,9 @@ struct PlayerControls: View {
var statusBar: some View {
HStack(spacing: 4) {
hidePlayerButton
#if os(iOS)
hidePlayerButton
#endif
Text(playbackStatus)
Spacer()
@@ -92,6 +96,9 @@ struct PlayerControls: View {
ToggleBackendButton()
Text("")
StreamControl()
#if os(macOS)
.frame(maxWidth: 160)
#endif
}
.foregroundColor(.primary)
.padding(.trailing, 4)
@@ -215,6 +222,7 @@ struct PlayerControls: View {
.padding()
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.foregroundColor(.primary)
.frame(width: size, height: size)
#if os(macOS)
@@ -226,7 +234,11 @@ struct PlayerControls: View {
}
var fullScreenLayout: Bool {
model.playingFullscreen || verticalSizeClass == .compact
#if !os(macOS)
model.playingFullscreen || verticalSizeClass == .compact
#else
model.playingFullscreen
#endif
}
}

View File

@@ -16,7 +16,8 @@ final class MPVViewController: UIViewController {
override func viewDidLoad() {
super.loadView()
glView = client.create(frame: view.frame)
client.create(frame: view.frame)
glView = client.glView
view.addSubview(glView)

View File

@@ -4,7 +4,7 @@ import SwiftUI
struct VideoDetailsPaddingModifier: ViewModifier {
static var defaultAdditionalDetailsPadding: Double {
#if os(macOS)
30
5
#else
10
#endif

View File

@@ -17,6 +17,7 @@ struct VideoPlayerView: View {
}
@State private var playerSize: CGSize = .zero
@State private var hoveringPlayer = false
@State private var fullScreenDetails = false
@Environment(\.colorScheme) private var colorScheme
@@ -32,6 +33,8 @@ struct VideoPlayerView: View {
@State private var motionManager: CMMotionManager!
@State private var orientation = UIInterfaceOrientation.portrait
@State private var lastOrientation: UIInterfaceOrientation?
#elseif os(macOS)
var mouseLocation: CGPoint { NSEvent.mouseLocation }
#endif
@EnvironmentObject<AccountsModel> private var accounts
@@ -95,12 +98,6 @@ struct VideoPlayerView: View {
#else
GeometryReader { geometry in
VStack(spacing: 0) {
if !playerControls.playingFullscreen {
#if os(macOS)
PlaybackBar()
#endif
}
if player.currentItem.isNil {
playerPlaceholder(geometry: geometry)
} else if player.playingInPictureInPicture {
@@ -140,22 +137,33 @@ struct VideoPlayerView: View {
}
}
.frame(maxWidth: fullScreenLayout ? .infinity : nil, maxHeight: fullScreenLayout ? .infinity : nil)
.onHover { hovering in
hoveringPlayer = hovering
hovering ? playerControls.show() : playerControls.hide()
}
#if os(iOS)
.onSwipeGesture(
up: {
withAnimation {
fullScreenDetails = true
}
},
down: { player.hide() }
)
.onHover { hovering in
hovering ? playerControls.show() : playerControls.hide()
.onSwipeGesture(
up: {
withAnimation {
fullScreenDetails = true
}
},
down: { player.hide() }
)
#elseif os(macOS)
.onAppear(perform: {
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
if hoveringPlayer {
playerControls.resetTimer()
}
return $0
}
})
#endif
.background(Color.black)
.background(Color.black)
if !playerControls.playingFullscreen {
Group {
@@ -197,12 +205,18 @@ struct VideoPlayerView: View {
}
}
.ignoresSafeArea(.all, edges: fullScreenLayout ? .vertical : Edge.Set())
.statusBar(hidden: playerControls.playingFullscreen)
.navigationBarHidden(true)
#if !os(macOS)
.statusBar(hidden: playerControls.playingFullscreen)
.navigationBarHidden(true)
#endif
}
var fullScreenLayout: Bool {
playerControls.playingFullscreen || verticalSizeClass == .compact
#if !os(macOS)
playerControls.playingFullscreen || verticalSizeClass == .compact
#else
playerControls.playingFullscreen
#endif
}
func playerPlaceholder(geometry: GeometryProxy) -> some View {