Skip to content

Commit

Permalink
mod: 全屏手势反向
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 14, 2024
1 parent 186d381 commit 516877f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
6 changes: 6 additions & 0 deletions lib/pages/setting/play_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ class _PlaySettingState extends State<PlaySetting> {
setKey: SettingBoxKey.enableQuickDouble,
defaultVal: true,
),
const SetSwitchItem(
title: '全屏手势反向',
subTitle: '默认播放器中部向上滑动进入全屏,向下退出\n开启后向下全屏,向上退出',
setKey: SettingBoxKey.fullScreenGestureReverse,
defaultVal: false,
),
const SetSwitchItem(
title: '弹幕开关',
subTitle: '展示弹幕',
Expand Down
21 changes: 13 additions & 8 deletions lib/plugin/pl_player/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late FullScreenMode mode;
late int defaultBtmProgressBehavior;
late bool enableQuickDouble;
late bool fullScreenGestureReverse;
late bool enableBackgroundPlay;

// 用于记录上一次全屏切换手势触发时间,避免误触
Expand Down Expand Up @@ -126,6 +127,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
defaultValue: BtmProgresBehavior.values.first.code);
enableQuickDouble =
setting.get(SettingBoxKey.enableQuickDouble, defaultValue: true);
fullScreenGestureReverse = setting.get(SettingBoxKey.fullScreenGestureReverse,
defaultValue: false);
enableBackgroundPlay =
setting.get(SettingBoxKey.enableBackgroundPlay, defaultValue: false);
Future.microtask(() async {
Expand Down Expand Up @@ -522,18 +525,20 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
// 全屏
final double dy = details.delta.dy;
const double threshold = 7.0; // 滑动阈值
void fullScreenTrigger() async {
lastFullScreenToggleTime = DateTime.now();
await widget.controller.triggerFullScreen();
}
if (dy > _distance && dy > threshold) {
if (_.isFullScreen.value) {
lastFullScreenToggleTime = DateTime.now();
// 下滑退出全屏
await widget.controller.triggerFullScreen(status: false);
// 下滑退出全屏
if (_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger();
}
_distance = 0.0;
} else if (dy < _distance && dy < -threshold) {
if (!_.isFullScreen.value) {
lastFullScreenToggleTime = DateTime.now();
// 上滑进入全屏
await widget.controller.triggerFullScreen();
// 上划进入全屏
if (!_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger();
}
_distance = 0.0;
}
Expand Down
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SettingBoxKey {

// youtube 双击快进快退
enableQuickDouble = 'enableQuickDouble',
fullScreenGestureReverse = 'fullScreenGestureReverse',
enableShowDanmaku = 'enableShowDanmaku',
enableBackgroundPlay = 'enableBackgroundPlay',

Expand Down

0 comments on commit 516877f

Please sign in to comment.