2022-08-28 22:48:49 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
extension VideoPlayerView {
|
|
|
|
var playerDragGesture: some Gesture {
|
2023-05-21 02:19:10 +05:30
|
|
|
DragGesture(minimumDistance: 30, coordinateSpace: .global)
|
2022-08-28 22:48:49 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.updating($dragGestureOffset) { value, state, _ in
|
|
|
|
guard isVerticalDrag else { return }
|
|
|
|
var translation = value.translation
|
|
|
|
translation.height = max(0, translation.height)
|
|
|
|
state = translation
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
.updating($dragGestureState) { _, state, _ in
|
|
|
|
state = true
|
|
|
|
}
|
|
|
|
.onChanged { value in
|
|
|
|
guard player.presentingPlayer,
|
2023-05-21 17:23:23 +05:30
|
|
|
!controlsOverlayModel.presenting,
|
|
|
|
dragGestureState else { return }
|
2022-08-28 22:48:49 +05:30
|
|
|
|
2022-09-01 23:31:01 +05:30
|
|
|
if player.controls.presentingControls, !player.musicMode {
|
|
|
|
player.controls.presentingControls = false
|
2022-08-28 22:48:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if player.musicMode {
|
|
|
|
player.backend.stopControlsUpdates()
|
|
|
|
}
|
|
|
|
|
|
|
|
let verticalDrag = value.translation.height
|
|
|
|
let horizontalDrag = value.translation.width
|
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
if viewDragOffset > 0, !isVerticalDrag {
|
|
|
|
isVerticalDrag = true
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-05-21 02:19:10 +05:30
|
|
|
if !isVerticalDrag,
|
|
|
|
horizontalPlayerGestureEnabled,
|
|
|
|
abs(horizontalDrag) > seekGestureSensitivity,
|
|
|
|
!isHorizontalDrag,
|
|
|
|
player.activeBackend == .mpv || !avPlayerUsesSystemControls
|
|
|
|
{
|
2022-08-28 22:48:49 +05:30
|
|
|
isHorizontalDrag = true
|
2022-08-29 17:25:23 +05:30
|
|
|
player.seek.onSeekGestureStart()
|
2022-08-28 22:48:49 +05:30
|
|
|
viewDragOffset = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if horizontalPlayerGestureEnabled, isHorizontalDrag {
|
2022-08-29 17:25:23 +05:30
|
|
|
player.seek.updateCurrentTime {
|
|
|
|
let time = player.backend.playerItemDuration?.seconds ?? 0
|
|
|
|
if player.seek.gestureStart.isNil {
|
|
|
|
player.seek.gestureStart = time
|
|
|
|
}
|
|
|
|
let timeSeek = (time / player.playerSize.width) * horizontalDrag * seekGestureSpeed
|
|
|
|
|
|
|
|
player.seek.gestureSeek = timeSeek
|
2022-08-28 22:48:49 +05:30
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard verticalDrag > 0 else { return }
|
|
|
|
viewDragOffset = verticalDrag
|
|
|
|
|
|
|
|
if verticalDrag > 60,
|
|
|
|
player.playingFullScreen
|
|
|
|
{
|
|
|
|
player.exitFullScreen(showControls: false)
|
|
|
|
#if os(iOS)
|
2023-05-23 20:59:10 +05:30
|
|
|
if Constants.isIPhone {
|
2022-08-28 22:48:49 +05:30
|
|
|
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onEnded { _ in
|
|
|
|
onPlayerDragGestureEnded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 21:28:40 +05:30
|
|
|
func onPlayerDragGestureEnded() {
|
2022-08-28 22:48:49 +05:30
|
|
|
if horizontalPlayerGestureEnabled, isHorizontalDrag {
|
|
|
|
isHorizontalDrag = false
|
2022-08-29 17:25:23 +05:30
|
|
|
player.seek.onSeekGestureEnd()
|
2022-08-28 22:48:49 +05:30
|
|
|
}
|
|
|
|
|
2023-05-21 02:19:10 +05:30
|
|
|
if viewDragOffset > 60,
|
|
|
|
player.playingFullScreen
|
|
|
|
{
|
|
|
|
#if os(iOS)
|
|
|
|
player.lockedOrientation = nil
|
|
|
|
#endif
|
|
|
|
player.exitFullScreen(showControls: false)
|
|
|
|
viewDragOffset = 0
|
|
|
|
return
|
|
|
|
}
|
2022-08-28 22:48:49 +05:30
|
|
|
isVerticalDrag = false
|
|
|
|
|
|
|
|
guard player.presentingPlayer,
|
2022-09-02 04:35:31 +05:30
|
|
|
!controlsOverlayModel.presenting else { return }
|
2022-08-28 22:48:49 +05:30
|
|
|
|
|
|
|
if viewDragOffset > 100 {
|
|
|
|
withAnimation(Constants.overlayAnimation) {
|
|
|
|
viewDragOffset = Self.hiddenOffset
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
withAnimation(Constants.overlayAnimation) {
|
|
|
|
viewDragOffset = 0
|
|
|
|
}
|
|
|
|
player.backend.setNeedsDrawing(true)
|
|
|
|
player.show()
|
|
|
|
|
|
|
|
if player.musicMode {
|
|
|
|
player.backend.startControlsUpdates()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|