diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 91e478ea..361a04f8 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -86,8 +86,6 @@ class _PLVideoPlayerState extends State final RxBool _mountSeekBackwardButton = false.obs; final RxBool _mountSeekForwardButton = false.obs; - final RxBool _hideSeekBackwardButton = false.obs; - final RxBool _hideSeekForwardButton = false.obs; final RxDouble _brightnessValue = 0.0.obs; final RxBool _brightnessIndicator = false.obs; @@ -1500,36 +1498,21 @@ class _PLVideoPlayerState extends State /// 点击 快进/快退 Obx( - () => Visibility( - visible: - _mountSeekBackwardButton.value || _mountSeekForwardButton.value, - child: Positioned.fill( - child: Row( - children: [ - Expanded( - child: _mountSeekBackwardButton.value - ? TweenAnimationBuilder( - tween: Tween( - begin: 0.0, - end: _hideSeekBackwardButton.value ? 0.0 : 1.0, - ), + () => _mountSeekBackwardButton.value || _mountSeekForwardButton.value + ? Positioned.fill( + child: Row( + children: [ + if (_mountSeekBackwardButton.value) + Expanded( + child: TweenAnimationBuilder( + tween: Tween(begin: 0.0, end: 1.0), duration: const Duration(milliseconds: 500), - builder: (BuildContext context, double value, - Widget? child) => - Opacity( + builder: (context, value, child) => Opacity( opacity: value, child: child, ), - onEnd: () { - if (_hideSeekBackwardButton.value) { - _hideSeekBackwardButton.value = false; - _mountSeekBackwardButton.value = false; - } - }, child: BackwardSeekIndicator( - onChanged: (Duration value) => {}, onSubmitted: (Duration value) { - _hideSeekBackwardButton.value = true; _mountSeekBackwardButton.value = false; final Player player = widget .plPlayerController.videoPlayerController!; @@ -1538,44 +1521,27 @@ class _PLVideoPlayerState extends State Duration.zero, player.state.duration, ); - plPlayerController.seekTo(result, - type: 'slider'); + plPlayerController.seekTo( + result, + type: 'slider', + ); plPlayerController.play(); }, ), - ) - : const SizedBox.shrink(), - ), - const Spacer(), - // Expanded( - // child: SizedBox( - // width: context.width / 4, - // ), - // ), - Expanded( - child: _mountSeekForwardButton.value - ? TweenAnimationBuilder( - tween: Tween( - begin: 0.0, - end: _hideSeekForwardButton.value ? 0.0 : 1.0, - ), + ), + ), + const Spacer(flex: 2), + if (_mountSeekForwardButton.value) + Expanded( + child: TweenAnimationBuilder( + tween: Tween(begin: 0.0, end: 1.0), duration: const Duration(milliseconds: 500), - builder: (BuildContext context, double value, - Widget? child) => - Opacity( + builder: (context, value, child) => Opacity( opacity: value, child: child, ), - onEnd: () { - if (_hideSeekForwardButton.value) { - _hideSeekForwardButton.value = false; - _mountSeekForwardButton.value = false; - } - }, child: ForwardSeekIndicator( - onChanged: (Duration value) => {}, onSubmitted: (Duration value) { - _hideSeekForwardButton.value = true; _mountSeekForwardButton.value = false; final Player player = widget .plPlayerController.videoPlayerController!; @@ -1584,18 +1550,19 @@ class _PLVideoPlayerState extends State Duration.zero, player.state.duration, ); - plPlayerController.seekTo(result, - type: 'slider'); + plPlayerController.seekTo( + result, + type: 'slider', + ); plPlayerController.play(); }, ), - ) - : const SizedBox.shrink(), + ), + ), + ], ), - ], - ), - ), - ), + ) + : const SizedBox.shrink(), ), ], ); diff --git a/lib/plugin/pl_player/widgets/backward_seek.dart b/lib/plugin/pl_player/widgets/backward_seek.dart index 4ccec9cb..599cdd13 100644 --- a/lib/plugin/pl_player/widgets/backward_seek.dart +++ b/lib/plugin/pl_player/widgets/backward_seek.dart @@ -3,11 +3,11 @@ import 'dart:async'; import 'package:flutter/material.dart'; class BackwardSeekIndicator extends StatefulWidget { - final void Function(Duration) onChanged; + // final void Function(Duration) onChanged; final void Function(Duration) onSubmitted; const BackwardSeekIndicator({ super.key, - required this.onChanged, + // required this.onChanged, required this.onSubmitted, }); @@ -28,18 +28,24 @@ class BackwardSeekIndicatorState extends State { }); } - void increment() { + @override + void dispose() { timer?.cancel(); - timer = Timer(const Duration(milliseconds: 400), () { - widget.onSubmitted.call(value); - }); - widget.onChanged.call(value); - // 重复点击 快退秒数累加10 - setState(() { - value += const Duration(seconds: 10); - }); + super.dispose(); } + // void increment() { + // timer?.cancel(); + // timer = Timer(const Duration(milliseconds: 400), () { + // widget.onSubmitted.call(value); + // }); + // widget.onChanged.call(value); + // // 重复点击 快退秒数累加10 + // setState(() { + // value += const Duration(seconds: 10); + // }); + // } + @override Widget build(BuildContext context) { return Container( @@ -53,32 +59,31 @@ class BackwardSeekIndicatorState extends State { end: Alignment.centerRight, ), ), - child: InkWell( - splashColor: const Color(0x44767676), - onTap: increment, - child: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Icon( - Icons.fast_rewind, - size: 24.0, - color: Colors.white, - ), - const SizedBox(height: 8.0), - Text( - '快退${value.inSeconds}秒', - style: const TextStyle( - fontSize: 12.0, - color: Colors.white, - ), - ), - ], + // child: InkWell( + // splashColor: const Color(0x44767676), + // onTap: increment, + alignment: Alignment.center, + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Icon( + Icons.fast_rewind, + size: 24.0, + color: Colors.white, ), - ), + const SizedBox(height: 8.0), + Text( + '快退${value.inSeconds}秒', + style: const TextStyle( + fontSize: 12.0, + color: Colors.white, + ), + ), + ], ), + // ), ); } } diff --git a/lib/plugin/pl_player/widgets/forward_seek.dart b/lib/plugin/pl_player/widgets/forward_seek.dart index 414c7d5a..27e50012 100644 --- a/lib/plugin/pl_player/widgets/forward_seek.dart +++ b/lib/plugin/pl_player/widgets/forward_seek.dart @@ -3,11 +3,11 @@ import 'dart:async'; import 'package:flutter/material.dart'; class ForwardSeekIndicator extends StatefulWidget { - final void Function(Duration) onChanged; + // final void Function(Duration) onChanged; final void Function(Duration) onSubmitted; const ForwardSeekIndicator({ super.key, - required this.onChanged, + // required this.onChanged, required this.onSubmitted, }); @@ -28,18 +28,24 @@ class ForwardSeekIndicatorState extends State { }); } - void increment() { + @override + void dispose() { timer?.cancel(); - timer = Timer(const Duration(milliseconds: 400), () { - widget.onSubmitted.call(value); - }); - widget.onChanged.call(value); - // 重复点击 快进秒数累加10 - setState(() { - value += const Duration(seconds: 10); - }); + super.dispose(); } + // void increment() { + // timer?.cancel(); + // timer = Timer(const Duration(milliseconds: 400), () { + // widget.onSubmitted.call(value); + // }); + // widget.onChanged.call(value); + // // 重复点击 快进秒数累加10 + // setState(() { + // value += const Duration(seconds: 10); + // }); + // } + @override Widget build(BuildContext context) { return Container( @@ -53,32 +59,31 @@ class ForwardSeekIndicatorState extends State { end: Alignment.centerRight, ), ), - child: InkWell( - splashColor: const Color(0x44767676), - onTap: increment, - child: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Icon( - Icons.fast_forward, - size: 24.0, - color: Colors.white, - ), - const SizedBox(height: 8.0), - Text( - '快进${value.inSeconds}秒', - style: const TextStyle( - fontSize: 12.0, - color: Colors.white, - ), - ), - ], + // child: InkWell( + // splashColor: const Color(0x44767676), + // onTap: increment, + alignment: Alignment.center, + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Icon( + Icons.fast_forward, + size: 24.0, + color: Colors.white, ), - ), + const SizedBox(height: 8.0), + Text( + '快进${value.inSeconds}秒', + style: const TextStyle( + fontSize: 12.0, + color: Colors.white, + ), + ), + ], ), + // ), ); } }