mod: 手势触发期间锁定分类;全屏手势延后到抬起时触发

This commit is contained in:
orz12
2024-07-20 19:30:13 +08:00
parent 685090f1c9
commit 6e4b234581

View File

@@ -91,7 +91,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late bool fullScreenGestureReverse; late bool fullScreenGestureReverse;
Offset _initialFocalPoint = Offset.zero; Offset _initialFocalPoint = Offset.zero;
String? _gestureDirection; // 'horizontal' or 'vertical' String? _gestureType;
//播放器放缩 //播放器放缩
bool interacting = false; bool interacting = false;
@@ -528,14 +528,16 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
interacting = true; interacting = true;
} }
_initialFocalPoint = details.localFocalPoint; _initialFocalPoint = details.localFocalPoint;
_gestureDirection = null; _gestureType = null;
}, },
onInteractionUpdate: (ScaleUpdateDetails details) { onInteractionUpdate: (ScaleUpdateDetails details) {
if (interacting) return; if (interacting) return;
if (details.pointerCount == 2) { Offset cumulativeDelta =
details.localFocalPoint - _initialFocalPoint;
if (details.pointerCount == 2 && cumulativeDelta.distance < 1.5) {
interacting = true; interacting = true;
_gestureDirection = null; _gestureType = null;
return; return;
} }
@@ -544,15 +546,27 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
RenderBox renderBox = RenderBox renderBox =
_playerKey.currentContext!.findRenderObject() as RenderBox; _playerKey.currentContext!.findRenderObject() as RenderBox;
if (_gestureDirection == null) { if (_gestureType == null) {
Offset cumulativeDelta =
details.localFocalPoint - _initialFocalPoint;
if (cumulativeDelta.distance < 1.5) return; if (cumulativeDelta.distance < 1.5) return;
if (cumulativeDelta.dx.abs() > 4 * cumulativeDelta.dy.abs()) { if (cumulativeDelta.dx.abs() > 4 * cumulativeDelta.dy.abs()) {
_gestureDirection = 'horizontal'; _gestureType = 'horizontal';
} else if (cumulativeDelta.dy.abs() > } else if (cumulativeDelta.dy.abs() >
4 * cumulativeDelta.dx.abs()) { 4 * cumulativeDelta.dx.abs()) {
_gestureDirection = 'vertical'; // _gestureType = 'vertical';
final double totalWidth = renderBox.size.width;
final double tapPosition = details.localFocalPoint.dx;
final double sectionWidth = totalWidth / 4;
if (tapPosition < sectionWidth) {
// 左边区域
_gestureType = 'left';
} else if (tapPosition < sectionWidth * 3) {
// 全屏
_gestureType = 'center';
} else {
// 右边区域
_gestureType = 'right';
}
} else { } else {
return; return;
} }
@@ -560,7 +574,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Offset delta = details.focalPointDelta; Offset delta = details.focalPointDelta;
if (_gestureDirection == 'horizontal') { if (_gestureType == 'horizontal') {
// live模式下禁用 // live模式下禁用
if (_.videoType.value == 'live') return; if (_.videoType.value == 'live') return;
final int curSliderPosition = final int curSliderPosition =
@@ -573,41 +587,31 @@ 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 (_gestureDirection == 'vertical') { } else if (_gestureType == 'left') {
// 垂直方向 音量/亮度调节
final double totalWidth = renderBox.size.width;
final double tapPosition = details.localFocalPoint.dx;
final double sectionWidth = totalWidth / 4;
if (tapPosition < sectionWidth) {
// 左边区域 👈 // 左边区域 👈
final double level = renderBox.size.height * 3; final double level = renderBox.size.height * 3;
final double brightness = final double brightness =
_brightnessValue.value - delta.dy / level; _brightnessValue.value - delta.dy / level;
final double result = brightness.clamp(0.0, 1.0); final double result = brightness.clamp(0.0, 1.0);
setBrightness(result); setBrightness(result);
} else if (tapPosition < sectionWidth * 3) { } else if (_gestureType == 'center') {
// 全屏 // 全屏
const double threshold = 10; // 滑动阈值 const double threshold = 7; // 滑动阈值
void fullScreenTrigger(bool status) async { // void fullScreenTrigger(bool status) async {
EasyThrottle.throttle( // EasyThrottle.throttle(
'fullScreen', const Duration(milliseconds: 1000), () { // 'fullScreen', const Duration(milliseconds: 1000), () {
_.triggerFullScreen(status: status); // _.triggerFullScreen(status: status);
}); // });
} // }
double cumulativeDy = double cumulativeDy =
details.localFocalPoint.dy - _initialFocalPoint.dy; details.localFocalPoint.dy - _initialFocalPoint.dy;
if (cumulativeDy > threshold) { if (cumulativeDy > threshold) {
// 下滑 _gestureType = 'center_down';
if (_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger(fullScreenGestureReverse);
}
} else if (cumulativeDy < -threshold) { } else if (cumulativeDy < -threshold) {
// 上划 _gestureType = 'center_up';
if (!_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger(!fullScreenGestureReverse);
} }
} } else if (_gestureType == 'right') {
} else {
// 右边区域 // 右边区域
final double level = renderBox.size.height * 0.5; final double level = renderBox.size.height * 0.5;
EasyThrottle.throttle( EasyThrottle.throttle(
@@ -617,16 +621,31 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
setVolume(result); setVolume(result);
}); });
} }
}
}, },
onInteractionEnd: (details) { onInteractionEnd: (ScaleEndDetails details) {
if (_.isSliderMoving.value) { if (_.isSliderMoving.value) {
_.onChangedSliderEnd(); _.onChangedSliderEnd();
_.seekTo(_.sliderPosition.value, type: 'slider'); _.seekTo(_.sliderPosition.value, type: 'slider');
} }
void fullScreenTrigger(bool status) async {
EasyThrottle.throttle(
'fullScreen', const Duration(milliseconds: 1000), () {
_.triggerFullScreen(status: status);
});
}
if (_gestureType == 'center_down') {
if (_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger(fullScreenGestureReverse);
}
} else if (_gestureType == 'center_up') {
if (!_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger(!fullScreenGestureReverse);
}
}
interacting = false; interacting = false;
_initialFocalPoint = Offset.zero; _initialFocalPoint = Offset.zero;
_gestureDirection = null; _gestureType = null;
}, },
child: Video( child: Video(
key: ValueKey('${_.videoFit.value}'), key: ValueKey('${_.videoFit.value}'),