From 767a82eb989ebd4b51b7d28432f7d751d5cc9e8e Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 16 Aug 2023 21:35:50 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E5=A2=9E=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E3=80=81=E5=85=BC=E5=AE=B9live=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/liveRoom/controller.dart | 2 +- lib/plugin/pl_player/controller.dart | 23 ++++++++++++--- lib/plugin/pl_player/view.dart | 42 +++++++++++++++++----------- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/lib/pages/liveRoom/controller.dart b/lib/pages/liveRoom/controller.dart index 31523b2f..5b176dc3 100644 --- a/lib/pages/liveRoom/controller.dart +++ b/lib/pages/liveRoom/controller.dart @@ -13,7 +13,7 @@ class LiveRoomController extends GetxController { // 静音状态 RxBool volumeOff = false.obs; PlPlayerController plPlayerController = - PlPlayerController.getInstance(controlsEnabled: false); + PlPlayerController.getInstance(videoType: 'live'); // MeeduPlayerController meeduPlayerController = MeeduPlayerController( // colorTheme: Theme.of(Get.context!).colorScheme.primary, diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 0cff9f4c..b291db1a 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -39,7 +39,7 @@ class PlPlayerController { /// final PlPlayerDataStatus dataStatus = PlPlayerDataStatus(); - bool controlsEnabled = true; + // bool controlsEnabled = false; /// 响应数据 // 播放位置 @@ -62,6 +62,8 @@ class PlPlayerController { final Rx _doubleSpeedStatus = false.obs; final Rx _controlsLock = false.obs; final Rx _isFullScreen = false.obs; + // 默认投稿视频格式 + static Rx _videoType = 'archive'.obs; final Rx _direction = 'horizontal'.obs; @@ -188,9 +190,12 @@ class PlPlayerController { Rx get playerCount => _playerCount; + /// + Rx get videoType => _videoType; + // 添加一个私有构造函数 PlPlayerController._() { - controlsEnabled = controlsEnabled; + _videoType = videoType; // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // if (status == PlayerStatus.playing) { // WakelockPlus.enable(); @@ -202,7 +207,7 @@ class PlPlayerController { // 获取实例 传参 static PlPlayerController getInstance({ - bool controlsEnabled = true, + String videoType = 'archive', List fits = const [ BoxFit.contain, BoxFit.cover, @@ -215,6 +220,7 @@ class PlPlayerController { // 如果实例尚未创建,则创建一个新实例 _instance ??= PlPlayerController._(); _instance!._playerCount.value += 1; + _videoType.value = videoType; return _instance!; } @@ -672,9 +678,18 @@ class PlPlayerController { } } - /// 设置长按倍速状态 + /// 设置长按倍速状态 live模式下禁用 void setDoubleSpeedStatus(bool val) { + if (videoType.value == 'live') { + return; + } _doubleSpeedStatus.value = val; + double currentSpeed = playbackSpeed; + if (val) { + setPlaybackSpeed(currentSpeed * 2); + } else { + setPlaybackSpeed(currentSpeed / 2); + } } /// 关闭控制栏 diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 0bc90c89..bacb2c71 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -262,7 +262,7 @@ class _PLVideoPlayerState extends State ), ), - /// 长按倍速 + /// 长按倍速 toast Obx( () => Align( alignment: Alignment.topCenter, @@ -301,7 +301,7 @@ class _PLVideoPlayerState extends State ), ), - /// 时间进度 + /// 时间进度 toast Obx( () => Align( alignment: Alignment.topCenter, @@ -482,6 +482,10 @@ class _PLVideoPlayerState extends State _.controls = !_.showControls.value; }, onDoubleTapDown: (details) { + // live模式下禁用 + if (_.videoType.value == 'live') { + return; + } final totalWidth = MediaQuery.of(context).size.width; final tapPosition = details.localPosition.dx; final sectionWidth = totalWidth / 3; @@ -501,17 +505,17 @@ class _PLVideoPlayerState extends State }, onLongPressStart: (detail) { feedBack(); - double currentSpeed = _.playbackSpeed; _.setDoubleSpeedStatus(true); - _.setPlaybackSpeed(currentSpeed * 2); }, onLongPressEnd: (details) { - double currentSpeed = _.playbackSpeed; _.setDoubleSpeedStatus(false); - _.setPlaybackSpeed(currentSpeed / 2); }, - // 水平位置 快进 + + /// 水平位置 快进 live模式下禁用 onHorizontalDragUpdate: (DragUpdateDetails details) { + if (_.videoType.value == 'live') { + return; + } final tapPosition = details.localPosition.dx; int curSliderPosition = _.sliderPosition.value.inSeconds; late int result; @@ -530,6 +534,9 @@ class _PLVideoPlayerState extends State _initTapPositoin = tapPosition; }, onHorizontalDragEnd: (DragEndDetails details) { + if (_.videoType.value == 'live') { + return; + } _.onChangedSliderEnd(); _.seekTo(_.sliderPosition.value); }, @@ -562,8 +569,6 @@ class _PLVideoPlayerState extends State _distance = 0.0; } _distance = dy; - - // triggerFullScreen(); } else { // 右边区域 👈 final volume = _volumeValue - delta / 100.0; @@ -576,9 +581,10 @@ class _PLVideoPlayerState extends State ), // 头部、底部控制条 - if (_.controlsEnabled) - Obx( - () => Column( + Obx( + () => Visibility( + visible: _.videoType.value != 'live', + child: Column( children: [ if (widget.headerControl != null) ClipRect( @@ -605,7 +611,9 @@ class _PLVideoPlayerState extends State ], ), ), - // 进度条 + ), + + /// 进度条 live模式下禁用 Obx( () { final int value = _.sliderPosition.value.inSeconds; @@ -658,9 +666,10 @@ class _PLVideoPlayerState extends State ), // 锁 - if (_.controlsEnabled) - Obx( - () => Align( + Obx( + () => Visibility( + visible: _.videoType.value != 'live', + child: Align( alignment: Alignment.centerLeft, child: FractionalTranslation( translation: const Offset(0.5, 0.0), @@ -680,6 +689,7 @@ class _PLVideoPlayerState extends State ), ), ), + ), // Obx(() { if (_.dataStatus.loading || _.isBuffering.value) {