2022-12-19 16:38:27 +05:30
|
|
|
import Defaults
|
2022-02-17 01:53:11 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerGestures: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
private var player = PlayerModel.shared
|
|
|
|
@ObservedObject private var model = PlayerControlsModel.shared
|
2022-02-17 01:53:11 +05:30
|
|
|
|
2022-12-19 16:38:27 +05:30
|
|
|
@Default(.gestureBackwardSeekDuration) private var gestureBackwardSeekDuration
|
|
|
|
@Default(.gestureForwardSeekDuration) private var gestureForwardSeekDuration
|
|
|
|
|
2022-02-17 01:53:11 +05:30
|
|
|
var body: some View {
|
|
|
|
HStack(spacing: 0) {
|
|
|
|
gestureRectangle
|
|
|
|
.tapRecognizer(
|
|
|
|
tapSensitivity: 0.2,
|
2022-07-10 23:21:46 +05:30
|
|
|
singleTapAction: { singleTapAction() },
|
2022-02-17 01:53:11 +05:30
|
|
|
doubleTapAction: {
|
2022-12-19 16:38:27 +05:30
|
|
|
let interval = TimeInterval(gestureBackwardSeekDuration) ?? 10
|
|
|
|
player.backend.seek(relative: .secondsInDefaultTimescale(-interval), seekType: .userInteracted)
|
2022-09-02 04:35:31 +05:30
|
|
|
},
|
|
|
|
anyTapAction: {
|
|
|
|
model.update()
|
2022-02-17 01:53:11 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
gestureRectangle
|
|
|
|
.tapRecognizer(
|
|
|
|
tapSensitivity: 0.2,
|
2022-07-10 23:21:46 +05:30
|
|
|
singleTapAction: { singleTapAction() },
|
2022-02-17 01:53:11 +05:30
|
|
|
doubleTapAction: {
|
|
|
|
player.backend.togglePlay()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
gestureRectangle
|
|
|
|
.tapRecognizer(
|
|
|
|
tapSensitivity: 0.2,
|
2022-07-10 23:21:46 +05:30
|
|
|
singleTapAction: { singleTapAction() },
|
2022-02-17 01:53:11 +05:30
|
|
|
doubleTapAction: {
|
2022-12-19 16:38:27 +05:30
|
|
|
let interval = TimeInterval(gestureForwardSeekDuration) ?? 10
|
|
|
|
player.backend.seek(relative: .secondsInDefaultTimescale(interval), seekType: .userInteracted)
|
2022-02-17 01:53:11 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:21:46 +05:30
|
|
|
func singleTapAction() {
|
|
|
|
if model.presentingOverlays {
|
|
|
|
withAnimation(PlayerControls.animation) {
|
|
|
|
model.hideOverlays()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
model.toggle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-17 01:53:11 +05:30
|
|
|
var gestureRectangle: some View {
|
|
|
|
Color.clear
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerGestures_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
PlayerGestures()
|
|
|
|
}
|
|
|
|
}
|