More controls improvements

This commit is contained in:
Arkadiusz Fal 2022-05-28 01:23:50 +02:00
parent 0ed014c9c5
commit 34990201dc
4 changed files with 36 additions and 25 deletions

View File

@ -43,7 +43,7 @@ final class PlayerControlsModel: ObservableObject {
func handlePresentationChange() { func handlePresentationChange() {
if presentingControls { if presentingControls {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
self?.player.backend.startControlsUpdates() self?.player?.backend.startControlsUpdates()
self?.resetTimer() self?.resetTimer()
} }
} else { } else {

View File

@ -58,14 +58,17 @@ struct PlayerControls: View {
.offset(y: 10) .offset(y: 10)
.zIndex(1) .zIndex(1)
bottomBar HStack {
Spacer()
#if os(macOS) bottomBar
.background(VisualEffectBlur(material: .hudWindow)) #if os(macOS)
#elseif os(iOS) .background(VisualEffectBlur(material: .hudWindow))
.background(VisualEffectBlur(blurStyle: .systemThinMaterial)) #elseif os(iOS)
#endif .background(VisualEffectBlur(blurStyle: .systemThinMaterial))
.mask(RoundedRectangle(cornerRadius: 3)) #endif
.mask(RoundedRectangle(cornerRadius: 3))
}
} }
.padding(.horizontal, 16) .padding(.horizontal, 16)
} }
@ -171,7 +174,9 @@ struct PlayerControls: View {
var buttonsBar: some View { var buttonsBar: some View {
HStack(spacing: 20) { HStack(spacing: 20) {
#if !os(tvOS) #if !os(tvOS)
hidePlayerButton #if os(iOS)
hidePlayerButton
#endif
fullscreenButton fullscreenButton
#if os(iOS) #if os(iOS)
@ -235,7 +240,11 @@ struct PlayerControls: View {
player.hide() player.hide()
player.closePiP() player.closePiP()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { var delay = 0.3
#if os(macOS)
delay = 0.0
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
player.closeCurrentItem() player.closeCurrentItem()
} }
} }
@ -260,7 +269,9 @@ struct PlayerControls: View {
player.avPlayerBackend.switchToMPVOnPipClose = true player.avPlayerBackend.switchToMPVOnPipClose = true
} }
player.exitFullScreen() #if !os(macOS)
player.exitFullScreen()
#endif
if player.activeBackend != PlayerBackendType.appleAVPlayer { if player.activeBackend != PlayerBackendType.appleAVPlayer {
player.saveTime { player.saveTime {
@ -329,8 +340,6 @@ struct PlayerControls: View {
var bottomBar: some View { var bottomBar: some View {
HStack { HStack {
Spacer()
Text(model.playbackTime) Text(model.playbackTime)
} }
.font(.system(size: 15)) .font(.system(size: 15))
@ -384,7 +393,7 @@ struct PlayerControls_Previews: PreviewProvider {
model.duration = .secondsInDefaultTimescale(120) model.duration = .secondsInDefaultTimescale(120)
let view = ZStack { let view = ZStack {
Color.red Color.gray
PlayerControls(player: PlayerModel()) PlayerControls(player: PlayerModel())
.injectFixtureEnvironmentObjects() .injectFixtureEnvironmentObjects()
@ -392,7 +401,7 @@ struct PlayerControls_Previews: PreviewProvider {
} }
return Group { return Group {
if #available(iOS 15.0, *) { if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
view.previewInterfaceOrientation(.landscapeLeft) view.previewInterfaceOrientation(.landscapeLeft)
} else { } else {
view view

View File

@ -38,7 +38,6 @@ struct TimelineView: View {
segmentsLayers segmentsLayers
} }
.mask(RoundedRectangle(cornerRadius: 3))
Circle() Circle()
.strokeBorder(.gray, lineWidth: 1) .strokeBorder(.gray, lineWidth: 1)
@ -114,7 +113,7 @@ struct TimelineView: View {
var projectedValue: Double { var projectedValue: Double {
let change = (dragOffset / size.width) * units let change = (dragOffset / size.width) * units
let projected = draggedFrom + change let projected = draggedFrom + change
return projected.isFinite ? (duration - projected < (0.03 * duration) ? duration : projected) : start return projected.isFinite ? (duration - projected < (0.01 * duration) ? duration : projected) : start
} }
var thumbOffset: Double { var thumbOffset: Double {

View File

@ -276,14 +276,17 @@ struct VideoPlayerView: View {
Spacer() Spacer()
} }
Button { #if os(iOS)
player.hide() Button {
} label: { player.hide()
Image(systemName: "xmark") } label: {
.font(.system(size: 40)) Image(systemName: "xmark")
} .font(.system(size: 40))
.padding(10) }
.foregroundColor(.gray) .buttonStyle(.plain)
.padding(10)
.foregroundColor(.gray)
#endif
} }
.contentShape(Rectangle()) .contentShape(Rectangle())
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: geometry.size.width / Self.defaultAspectRatio) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: geometry.size.width / Self.defaultAspectRatio)