2022-08-06 13:27:34 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerBackendView: View {
|
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2022-08-06 13:27:34 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ZStack(alignment: .top) {
|
|
|
|
Group {
|
|
|
|
switch player.activeBackend {
|
|
|
|
case .mpv:
|
|
|
|
player.mpvPlayerView
|
|
|
|
case .appleAVPlayer:
|
|
|
|
player.avPlayerView
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.overlay(GeometryReader { proxy in
|
|
|
|
Color.clear
|
2022-08-13 14:46:45 +00:00
|
|
|
.onAppear { player.playerSize = proxy.size }
|
2022-08-06 13:27:34 +00:00
|
|
|
.onChange(of: proxy.size) { _ in player.playerSize = proxy.size }
|
|
|
|
.onChange(of: player.controls.presentingOverlays) { _ in player.playerSize = proxy.size }
|
|
|
|
})
|
|
|
|
#if os(iOS)
|
|
|
|
.padding(.top, player.playingFullScreen && verticalSizeClass == .regular ? 20 : 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
PlayerGestures()
|
2022-11-24 20:36:05 +00:00
|
|
|
PlayerControls()
|
2022-08-06 13:27:34 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.padding(.top, controlsTopPadding)
|
|
|
|
.padding(.bottom, controlsBottomPadding)
|
|
|
|
#endif
|
2022-08-28 22:29:29 +00:00
|
|
|
#else
|
|
|
|
hiddenControlsButton
|
2022-08-06 13:27:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(iOS)
|
2022-09-01 23:05:31 +00:00
|
|
|
.statusBarHidden(player.playingFullScreen)
|
2022-08-06 13:27:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
var controlsTopPadding: Double {
|
2022-09-01 23:05:31 +00:00
|
|
|
guard player.playingFullScreen else { return 0 }
|
2022-08-06 13:27:34 +00:00
|
|
|
|
|
|
|
if UIDevice.current.userInterfaceIdiom != .pad {
|
2022-08-07 12:11:57 +00:00
|
|
|
return verticalSizeClass == .compact ? SafeArea.insets.top : 0
|
2022-08-06 13:27:34 +00:00
|
|
|
} else {
|
2022-08-07 12:11:57 +00:00
|
|
|
return SafeArea.insets.top.isZero ? SafeArea.insets.bottom : SafeArea.insets.top
|
2022-08-06 13:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var controlsBottomPadding: Double {
|
2022-09-01 23:05:31 +00:00
|
|
|
guard player.playingFullScreen else { return 0 }
|
2022-08-06 13:27:34 +00:00
|
|
|
|
|
|
|
if UIDevice.current.userInterfaceIdiom != .pad {
|
2022-09-01 23:05:31 +00:00
|
|
|
return player.playingFullScreen && verticalSizeClass == .compact ? SafeArea.insets.bottom : 0
|
2022-08-06 13:27:34 +00:00
|
|
|
} else {
|
2022-09-01 23:05:31 +00:00
|
|
|
return player.playingFullScreen ? SafeArea.insets.bottom : 0
|
2022-08-06 13:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-08-28 22:29:29 +00:00
|
|
|
|
|
|
|
#if os(tvOS)
|
|
|
|
private var hiddenControlsButton: some View {
|
|
|
|
VStack {
|
|
|
|
Button {
|
|
|
|
player.controls.show()
|
|
|
|
} label: {
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
.offset(y: -100)
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
.background(Color.clear)
|
|
|
|
.foregroundColor(.clear)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-08-06 13:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerBackendView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
PlayerBackendView()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|