mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: 改写滑动手势判别方式,提高灵敏度
This commit is contained in:
@@ -89,6 +89,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
late int defaultBtmProgressBehavior;
|
late int defaultBtmProgressBehavior;
|
||||||
late bool enableQuickDouble;
|
late bool enableQuickDouble;
|
||||||
late bool fullScreenGestureReverse;
|
late bool fullScreenGestureReverse;
|
||||||
|
|
||||||
|
Offset _initialFocalPoint = Offset.zero;
|
||||||
|
String? _gestureDirection; // 'horizontal' or 'vertical'
|
||||||
//播放器放缩
|
//播放器放缩
|
||||||
bool interacting = false;
|
bool interacting = false;
|
||||||
|
|
||||||
@@ -524,22 +527,40 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
if (details.pointerCount == 2) {
|
if (details.pointerCount == 2) {
|
||||||
interacting = true;
|
interacting = true;
|
||||||
}
|
}
|
||||||
|
_initialFocalPoint = details.localFocalPoint;
|
||||||
|
_gestureDirection = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
onInteractionUpdate: (ScaleUpdateDetails details) {
|
onInteractionUpdate: (ScaleUpdateDetails details) {
|
||||||
if (interacting) return;
|
if (interacting) return;
|
||||||
if (details.pointerCount == 2) {
|
if (details.pointerCount == 2) {
|
||||||
interacting = true;
|
interacting = true;
|
||||||
|
_gestureDirection = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 锁定时禁用
|
/// 锁定时禁用
|
||||||
if (_.controlsLock.value) return;
|
if (_.controlsLock.value) return;
|
||||||
Offset delta = details.focalPointDelta;
|
|
||||||
if (delta.distance < 2) return;
|
|
||||||
RenderBox renderBox =
|
RenderBox renderBox =
|
||||||
_playerKey.currentContext!.findRenderObject() as RenderBox;
|
_playerKey.currentContext!.findRenderObject() as RenderBox;
|
||||||
// if onHorizontalDragUpdate
|
|
||||||
if (delta.dx.abs() > 5 * delta.dy.abs()) {
|
if (_gestureDirection == null) {
|
||||||
|
Offset cumulativeDelta =
|
||||||
|
details.localFocalPoint - _initialFocalPoint;
|
||||||
|
if (cumulativeDelta.distance < 1.5) return;
|
||||||
|
if (cumulativeDelta.dx.abs() > 4 * cumulativeDelta.dy.abs()) {
|
||||||
|
_gestureDirection = 'horizontal';
|
||||||
|
} else if (cumulativeDelta.dy.abs() >
|
||||||
|
4 * cumulativeDelta.dx.abs()) {
|
||||||
|
_gestureDirection = 'vertical';
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Offset delta = details.focalPointDelta;
|
||||||
|
|
||||||
|
if (_gestureDirection == 'horizontal') {
|
||||||
// live模式下禁用
|
// live模式下禁用
|
||||||
if (_.videoType.value == 'live') return;
|
if (_.videoType.value == 'live') return;
|
||||||
final int curSliderPosition =
|
final int curSliderPosition =
|
||||||
@@ -552,7 +573,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
pos.clamp(Duration.zero, _.duration.value);
|
pos.clamp(Duration.zero, _.duration.value);
|
||||||
_.onUpdatedSliderProgress(result);
|
_.onUpdatedSliderProgress(result);
|
||||||
_.onChangedSliderStart();
|
_.onChangedSliderStart();
|
||||||
} else if (delta.dx.abs() * 5 < delta.dy.abs()) {
|
} else if (_gestureDirection == 'vertical') {
|
||||||
// 垂直方向 音量/亮度调节
|
// 垂直方向 音量/亮度调节
|
||||||
final double totalWidth = renderBox.size.width;
|
final double totalWidth = renderBox.size.width;
|
||||||
final double tapPosition = details.localFocalPoint.dx;
|
final double tapPosition = details.localFocalPoint.dx;
|
||||||
@@ -566,21 +587,21 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
setBrightness(result);
|
setBrightness(result);
|
||||||
} else if (tapPosition < sectionWidth * 3) {
|
} else if (tapPosition < sectionWidth * 3) {
|
||||||
// 全屏
|
// 全屏
|
||||||
const double threshold = 7.0; // 滑动阈值
|
const double threshold = 10; // 滑动阈值
|
||||||
void fullScreenTrigger(bool status) async {
|
void fullScreenTrigger(bool status) async {
|
||||||
EasyThrottle.throttle(
|
EasyThrottle.throttle(
|
||||||
'fullScreen', const Duration(milliseconds: 500), () {
|
'fullScreen', const Duration(milliseconds: 1000), () {
|
||||||
// widget.controller.triggerFullScreen(status: status);
|
|
||||||
_.triggerFullScreen(status: status);
|
_.triggerFullScreen(status: status);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
double cumulativeDy =
|
||||||
if (delta.dy > threshold) {
|
details.localFocalPoint.dy - _initialFocalPoint.dy;
|
||||||
|
if (cumulativeDy > threshold) {
|
||||||
// 下滑
|
// 下滑
|
||||||
if (_.isFullScreen.value ^ fullScreenGestureReverse) {
|
if (_.isFullScreen.value ^ fullScreenGestureReverse) {
|
||||||
fullScreenTrigger(fullScreenGestureReverse);
|
fullScreenTrigger(fullScreenGestureReverse);
|
||||||
}
|
}
|
||||||
} else if (delta.dy < -threshold) {
|
} else if (cumulativeDy < -threshold) {
|
||||||
// 上划
|
// 上划
|
||||||
if (!_.isFullScreen.value ^ fullScreenGestureReverse) {
|
if (!_.isFullScreen.value ^ fullScreenGestureReverse) {
|
||||||
fullScreenTrigger(!fullScreenGestureReverse);
|
fullScreenTrigger(!fullScreenGestureReverse);
|
||||||
@@ -604,6 +625,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
_.seekTo(_.sliderPosition.value, type: 'slider');
|
_.seekTo(_.sliderPosition.value, type: 'slider');
|
||||||
}
|
}
|
||||||
interacting = false;
|
interacting = false;
|
||||||
|
_initialFocalPoint = Offset.zero;
|
||||||
|
_gestureDirection = null;
|
||||||
},
|
},
|
||||||
child: Video(
|
child: Video(
|
||||||
key: ValueKey('${_.videoFit.value}'),
|
key: ValueKey('${_.videoFit.value}'),
|
||||||
|
|||||||
Reference in New Issue
Block a user