From 587870ad719f3df89cfe83ccb6abbb4725c67216 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Thu, 27 Feb 2025 16:52:33 +0800 Subject: [PATCH] fix: player key Signed-off-by: bggRGjQaUbCoE --- lib/pages/video/detail/view_v.dart | 30 +++++++++++++++------------- lib/plugin/pl_player/controller.dart | 10 +++++----- lib/plugin/pl_player/view.dart | 5 +++-- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/pages/video/detail/view_v.dart b/lib/pages/video/detail/view_v.dart index dc3a3d52..0026b7d0 100644 --- a/lib/pages/video/detail/view_v.dart +++ b/lib/pages/video/detail/view_v.dart @@ -243,25 +243,27 @@ class _VideoDetailPageVState extends State // 播放器状态监听 void playerListener(PlayerStatus? status) async { try { - bool isPlaying = status == PlayerStatus.playing; - if (isPlaying) { - if (videoDetailController.isExpanding.not && - videoDetailController.scrollCtr.offset != 0 && - videoDetailController.animationController.isAnimating.not) { - videoDetailController.isExpanding = true; - videoDetailController.animationController.forward( - from: 1 - - videoDetailController.scrollCtr.offset / - videoDetailController.videoHeight); + if (videoDetailController.scrollCtr.hasClients) { + bool isPlaying = status == PlayerStatus.playing; + if (isPlaying) { + if (videoDetailController.isExpanding.not && + videoDetailController.scrollCtr.offset != 0 && + videoDetailController.animationController.isAnimating.not) { + videoDetailController.isExpanding = true; + videoDetailController.animationController.forward( + from: 1 - + videoDetailController.scrollCtr.offset / + videoDetailController.videoHeight); + } else { + if (videoDetailController.scrollKey.currentState?.mounted == true) { + videoDetailController.scrollKey.currentState?.setState(() {}); + } + } } else { if (videoDetailController.scrollKey.currentState?.mounted == true) { videoDetailController.scrollKey.currentState?.setState(() {}); } } - } else { - if (videoDetailController.scrollKey.currentState?.mounted == true) { - videoDetailController.scrollKey.currentState?.setState(() {}); - } } } catch (e) { debugPrint('handle playe status: $e'); diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index b4d59f40..1d32f6cc 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -289,8 +289,6 @@ class PlPlayerController { // 播放顺序相关 PlayRepeat playRepeat = PlayRepeat.pause; - GlobalKey key = GlobalKey(); - TextStyle get subTitleStyle => TextStyle( height: 1.5, fontSize: @@ -313,10 +311,12 @@ class PlPlayerController { textScaleFactor: MediaQuery.textScalerOf(Get.context!).scale(1), ); + late Function getPlayerKey; + void updateSubtitleStyle() { - key.currentState?.update( - subtitleViewConfiguration: subtitleViewConfiguration, - ); + getPlayerKey().currentState?.update( + subtitleViewConfiguration: subtitleViewConfiguration, + ); } void updateSliderPositionSecond() { diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index f6da17f0..703b1b20 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -84,6 +84,7 @@ class _PLVideoPlayerState extends State late BangumiIntroController? bangumiIntroController; final GlobalKey _playerKey = GlobalKey(); + final GlobalKey key = GlobalKey(); final RxBool _mountSeekBackwardButton = false.obs; final RxBool _mountSeekForwardButton = false.obs; @@ -160,7 +161,6 @@ class _PLVideoPlayerState extends State @override void initState() { super.initState(); - plPlayerController.key = GlobalKey(); animationController = AnimationController( vsync: this, duration: const Duration(milliseconds: 100)); videoController = plPlayerController.videoController!; @@ -169,6 +169,7 @@ class _PLVideoPlayerState extends State plPlayerController.headerControl = widget.headerControl; plPlayerController.bottomControl = widget.bottomControl; plPlayerController.danmuWidget = widget.danmuWidget; + plPlayerController.getPlayerKey = () => key; defaultBtmProgressBehavior = GStorage.setting.get( SettingBoxKey.btmProgressBehavior, defaultValue: BtmProgressBehavior.values.first.code); @@ -898,7 +899,7 @@ class _PLVideoPlayerState extends State flipY: plPlayerController.flipY.value, child: Video( fill: widget.fill ?? Colors.black, - key: plPlayerController.key, + key: key, controller: videoController, controls: NoVideoControls, pauseUponEnteringBackgroundMode: