yattee/Shared/Player/PlayerGestures.swift

77 lines
2.5 KiB
Swift
Raw Normal View History

2022-12-19 11:08:27 +00:00
import Defaults
2022-02-16 20:23:11 +00:00
import SwiftUI
struct PlayerGestures: View {
private var player = PlayerModel.shared
@ObservedObject private var model = PlayerControlsModel.shared
2022-02-16 20:23:11 +00:00
@Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls
var showGestures: Bool {
player.activeBackend == .mpv || !avPlayerUsesSystemControls
}
2022-02-16 20:23:11 +00:00
var body: some View {
HStack(spacing: 0) {
if showGestures {
gestureRectangle
.tapRecognizer(
tapSensitivity: 0.2,
doubleTapAction: {
model.presentingControls = false
let interval = TimeInterval(Defaults[.gestureBackwardSeekDuration]) ?? 10
player.backend.seek(relative: .secondsInDefaultTimescale(-interval), seekType: .userInteracted)
},
anyTapAction: {
singleTapAction()
model.update()
}
)
2022-02-16 20:23:11 +00:00
gestureRectangle
.tapRecognizer(
tapSensitivity: 0.2,
doubleTapAction: {
model.presentingControls = false
player.backend.togglePlay()
},
anyTapAction: singleTapAction
)
2022-02-16 20:23:11 +00:00
gestureRectangle
.tapRecognizer(
tapSensitivity: 0.2,
doubleTapAction: {
model.presentingControls = false
let interval = TimeInterval(Defaults[.gestureForwardSeekDuration]) ?? 10
player.backend.seek(relative: .secondsInDefaultTimescale(interval), seekType: .userInteracted)
},
anyTapAction: singleTapAction
)
}
2022-02-16 20:23:11 +00:00
}
}
2022-07-10 17:51:46 +00:00
func singleTapAction() {
if model.presentingOverlays {
withAnimation(PlayerControls.animation) {
model.hideOverlays()
}
} else {
model.toggle()
}
}
2022-02-16 20:23:11 +00:00
var gestureRectangle: some View {
Color.clear
.contentShape(Rectangle())
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
struct PlayerGestures_Previews: PreviewProvider {
static var previews: some View {
PlayerGestures()
}
}