diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index cd9ed38f5..a10c0824c 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -44,7 +44,6 @@ class _LiveRoomPageState extends State bool isShowCover = true; bool isPlay = true; - Floating? floating; StreamSubscription? _listener; @@ -69,9 +68,6 @@ class _LiveRoomPageState extends State tag: heroTag, ); PlPlayerController.setPlayCallBack(playCallBack); - if (Platform.isAndroid) { - floating = Floating(); - } videoSourceInit(); _futureBuilderFuture = _liveRoomController.queryLiveInfo(); plPlayerController @@ -145,7 +141,6 @@ class _LiveRoomPageState extends State final GlobalKey videoPlayerKey = GlobalKey(); final GlobalKey playerKey = GlobalKey(); - double? padding; Widget videoPlayerPanel({Color? fill, Alignment? alignment}) { return PopScope( @@ -167,7 +162,6 @@ class _LiveRoomPageState extends State plPlayerController: plPlayerController, headerControl: LiveHeaderControl( plPlayerController: plPlayerController, - floating: floating, onSendDanmaku: onSendDanmaku, ), bottomControl: BottomControl( @@ -243,7 +237,7 @@ class _LiveRoomPageState extends State ), ), SafeArea( - top: false, + top: !isFullScreen, left: !isFullScreen, right: !isFullScreen, bottom: false, @@ -251,10 +245,6 @@ class _LiveRoomPageState extends State ? Obx( () { if (_liveRoomController.isPortrait.value) { - if (padding == null) { - final padding = MediaQuery.paddingOf(context); - this.padding = padding.bottom + padding.top; - } return _buildPP; } return _buildPH; @@ -285,51 +275,41 @@ class _LiveRoomPageState extends State _buildAppBar, Column( children: [ - Obx( - () => Container( - color: Colors.black, - width: Get.width, - margin: isFullScreen - ? null - : EdgeInsets.only( - top: 56 + MediaQuery.paddingOf(context).top, + Expanded( + child: Stack( + clipBehavior: Clip.none, + children: [ + Obx( + () => Container( + margin: isFullScreen + ? null + : const EdgeInsets.only(top: 56), + color: Colors.black, + child: videoPlayerPanel( + alignment: isFullScreen ? null : Alignment.topCenter, ), - height: isFullScreen - ? Get.height - - (context.orientation == Orientation.landscape - ? 0 - : MediaQuery.paddingOf(context).top) - : Get.height - 56 - 85 - padding!, - child: videoPlayerPanel( - alignment: isFullScreen ? null : Alignment.topCenter, - ), + ), + ), + Obx( + () => isFullScreen + ? const SizedBox.shrink() + : Positioned( + left: 0, + right: 0, + bottom: 55, + child: SizedBox( + height: 125, + child: _buildChatWidget(true), + ), + ), + ), + ], ), ), + Obx(() => + isFullScreen ? const SizedBox.shrink() : _buildInputWidget), ], ), - Obx( - () => isFullScreen - ? const SizedBox.shrink() - : Positioned( - left: 0, - right: 0, - bottom: 125 + MediaQuery.paddingOf(context).bottom, - child: SizedBox( - height: 125, - child: _buildChatWidget(true), - ), - ), - ), - Obx( - () => isFullScreen - ? const SizedBox.shrink() - : Positioned( - left: 0, - right: 0, - bottom: 0, - child: _buildInputWidget, - ), - ), ], ); @@ -341,12 +321,9 @@ class _LiveRoomPageState extends State return OrientationBuilder( builder: (BuildContext context, Orientation orientation) { if (Platform.isAndroid) { - return PiPSwitcher( - getChildWhenDisabled: () => - childWhenDisabled(orientation == Orientation.portrait), - getChildWhenEnabled: () => videoPlayerPanel(), - floating: floating, - ); + return Floating().isPipMode + ? videoPlayerPanel() + : childWhenDisabled(orientation == Orientation.portrait); } else { return childWhenDisabled(orientation == Orientation.portrait); } diff --git a/lib/pages/live_room/widgets/header_control.dart b/lib/pages/live_room/widgets/header_control.dart index 1fee88f48..9e81b5180 100644 --- a/lib/pages/live_room/widgets/header_control.dart +++ b/lib/pages/live_room/widgets/header_control.dart @@ -10,12 +10,10 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart class LiveHeaderControl extends StatelessWidget implements PreferredSizeWidget { const LiveHeaderControl({ required this.plPlayerController, - this.floating, required this.onSendDanmaku, super.key, }); - final Floating? floating; final PlPlayerController plPlayerController; final VoidCallback onSendDanmaku; @@ -77,9 +75,15 @@ class LiveHeaderControl extends StatelessWidget implements PreferredSizeWidget { ), onPressed: () async { try { - if ((await floating?.isPipAvailable) == true) { + var floating = Floating(); + if ((await floating.isPipAvailable) == true) { plPlayerController.hiddenControls(false); - floating!.enable(const EnableManual()); + floating.enable( + plPlayerController.direction.value == 'vertical' + ? const EnableManual( + aspectRatio: Rational.vertical()) + : const EnableManual(), + ); } } catch (_) {} }, diff --git a/lib/pages/video/controller.dart b/lib/pages/video/controller.dart index 0f9d041c3..82b14bcae 100644 --- a/lib/pages/video/controller.dart +++ b/lib/pages/video/controller.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:io'; import 'dart:math'; import 'dart:ui'; @@ -48,7 +47,6 @@ import 'package:PiliPlus/utils/video_utils.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart'; -import 'package:floating/floating.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_volume_controller/flutter_volume_controller.dart'; @@ -103,7 +101,6 @@ class VideoDetailController extends GetxController // 亮度 double? brightness; - Floating? floating; late final headerCtrKey = GlobalKey(); Box get setting => GStorage.setting; @@ -287,10 +284,6 @@ class VideoDetailController extends GetxController if (autoPlay.value) isShowCover.value = false; danmakuCid.value = cid.value; - if (Platform.isAndroid) { - floating = Floating(); - } - // 预设的解码格式 cacheDecode = setting.get(SettingBoxKey.defaultDecode, defaultValue: VideoDecodeFormatType.values.last.code); @@ -1109,6 +1102,8 @@ class VideoDetailController extends GetxController } setSubtitle(vttSubtitlesIndex.value); }, + width: data.dash!.video!.first.width, + height: data.dash!.video!.first.height, ); initSkip(); @@ -1121,9 +1116,7 @@ class VideoDetailController extends GetxController _getDmTrend(); } - if (defaultST != null) { - defaultST = null; - } + defaultST = null; } bool isQuerying = false; diff --git a/lib/pages/video/view.dart b/lib/pages/video/view.dart index 75a269f3a..e67b2ee2f 100644 --- a/lib/pages/video/view.dart +++ b/lib/pages/video/view.dart @@ -86,7 +86,6 @@ class _VideoDetailPageVState extends State late bool autoExitFullscreen; late bool autoPlayEnable; late bool enableVerticalExpand; - late bool autoPiP; late bool pipNoDanmaku; late bool removeSafeArea; bool isShowing = true; @@ -142,7 +141,6 @@ class _VideoDetailPageVState extends State setting.get(SettingBoxKey.enableAutoExit, defaultValue: true); autoPlayEnable = setting.get(SettingBoxKey.autoPlayEnable, defaultValue: false); - autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false); pipNoDanmaku = setting.get(SettingBoxKey.pipNoDanmaku, defaultValue: false); enableVerticalExpand = setting.get(SettingBoxKey.enableVerticalExpand, defaultValue: false); @@ -151,17 +149,6 @@ class _VideoDetailPageVState extends State if (removeSafeArea) hideStatusBar(); videoSourceInit(); autoScreen(); - if (Platform.isAndroid) { - Utils.channel.setMethodCallHandler((call) async { - if (call.method == 'onUserLeaveHint') { - if (autoPiP && - plPlayerController?.playerStatus.status.value == - PlayerStatus.playing) { - enterPip(); - } - } - }); - } if (videoDetailController.showReply) { WidgetsBinding.instance.addPostFrameCallback((_) { @@ -276,9 +263,8 @@ class _VideoDetailPageVState extends State } } // 播放完展示控制栏 - if (videoDetailController.floating != null && !notExitFlag) { - PiPStatus currentStatus = - await videoDetailController.floating!.pipStatus; + if (Platform.isAndroid && !notExitFlag) { + PiPStatus currentStatus = await Floating().pipStatus; if (currentStatus == PiPStatus.disabled) { plPlayerController!.onLockControl(false); } @@ -454,17 +440,6 @@ class _VideoDetailPageVState extends State : Theme.of(context); } - void enterPip() { - if (Get.currentRoute.startsWith('/video') && - videoDetailController.floating != null) { - PageUtils.enterPip( - videoDetailController.floating!, - videoDetailController.data.dash!.video!.first.width!, - videoDetailController.data.dash!.video!.first.height!, - ); - } - } - void animListener() { if (videoDetailController.animationController.isForwardOrCompleted) { cal(); @@ -1413,7 +1388,6 @@ class _VideoDetailPageVState extends State key: videoDetailController.headerCtrKey, controller: videoDetailController.plPlayerController, videoDetailCtr: videoDetailController, - floating: videoDetailController.floating, heroTag: heroTag, ), danmuWidget: Obx( @@ -1431,11 +1405,7 @@ class _VideoDetailPageVState extends State Widget autoChoose(Widget childWhenDisabled) { if (Platform.isAndroid) { - return PiPSwitcher( - getChildWhenDisabled: () => childWhenDisabled, - getChildWhenEnabled: () => childWhenEnabled, - floating: videoDetailController.floating, - ); + return Floating().isPipMode ? childWhenEnabled : childWhenDisabled; } return childWhenDisabled; } diff --git a/lib/pages/video/widgets/header_control.dart b/lib/pages/video/widgets/header_control.dart index 77a9aacae..33ab42eaf 100644 --- a/lib/pages/video/widgets/header_control.dart +++ b/lib/pages/video/widgets/header_control.dart @@ -47,13 +47,11 @@ class HeaderControl extends StatefulWidget implements PreferredSizeWidget { const HeaderControl({ required this.controller, required this.videoDetailCtr, - this.floating, required this.heroTag, super.key, }); final PlPlayerController controller; final VideoDetailController videoDetailCtr; - final Floating? floating; final String heroTag; @override @@ -2118,8 +2116,7 @@ class HeaderControlState extends State { padding: WidgetStateProperty.all(EdgeInsets.zero), ), onPressed: () async { - bool canUsePiP = widget.floating != null && - await widget.floating!.isPipAvailable; + bool canUsePiP = await Floating().isPipAvailable; widget.controller.hiddenControls(false); if (canUsePiP) { bool enableBackgroundPlay = setting.get( @@ -2189,10 +2186,9 @@ class HeaderControlState extends State { } if (!context.mounted) return; PageUtils.enterPip( - widget.floating!, - widget + width: widget .videoDetailCtr.data.dash!.video!.first.width!, - widget + height: widget .videoDetailCtr.data.dash!.video!.first.height!, ); } diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 9428e2a50..40874bfc8 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -23,6 +23,7 @@ import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart'; import 'package:PiliPlus/services/service_locator.dart'; import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/feed_back.dart'; +import 'package:PiliPlus/utils/page_utils.dart' show PageUtils; import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:canvas_danmaku/canvas_danmaku.dart'; @@ -116,6 +117,8 @@ class PlPlayerController { dynamic _seasonId; dynamic _subType; int _heartDuration = 0; + int? width; + int? height; late DataSource dataSource; @@ -243,6 +246,15 @@ class PlPlayerController { /// 弹幕开关 RxBool isOpenDanmu = false.obs; + bool autoPiP = + GStorage.setting.get(SettingBoxKey.autoPiP, defaultValue: false); + + void enterPip() { + if (Get.currentRoute.startsWith('/video')) { + PageUtils.enterPip(width: width, height: height); + } + } + /// 弹幕权重 int danmakuWeight = 0; late RuleFilter filters; @@ -486,6 +498,16 @@ class PlPlayerController { enableHeart = false; } + if (Platform.isAndroid) { + Utils.channel.setMethodCallHandler((call) async { + if (call.method == 'onUserLeaveHint') { + if (autoPiP && playerStatus.status.value == PlayerStatus.playing) { + enterPip(); + } + } + }); + } + // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // if (status == PlayerStatus.playing) { // WakelockPlus.enable(); @@ -520,8 +542,8 @@ class PlPlayerController { Duration? seekTo, // 初始化播放速度 double speed = 1.0, - double? width, - double? height, + int? width, + int? height, Duration? duration, // 方向 String? direction, @@ -534,6 +556,8 @@ class PlPlayerController { VoidCallback? callback, }) async { try { + this.width = width; + this.height = height; this.dataSource = dataSource; this.segmentList.value = segmentList ?? []; this.viewPointList.value = viewPointList ?? []; @@ -568,8 +592,8 @@ class PlPlayerController { return; } // 配置Player 音轨、字幕等等 - _videoPlayerController = await _createVideoController( - dataSource, _looping, width, height, seekTo); + _videoPlayerController = + await _createVideoController(dataSource, _looping, seekTo); callback?.call(); // 获取视频时长 00:00 _duration.value = duration ?? _videoPlayerController!.state.duration; @@ -676,8 +700,6 @@ class PlPlayerController { Future _createVideoController( DataSource dataSource, PlaylistMode looping, - double? width, - double? height, Duration? seekTo, ) async { // 每次配置时先移除监听 diff --git a/lib/utils/page_utils.dart b/lib/utils/page_utils.dart index e2633c933..5219ca8bb 100644 --- a/lib/utils/page_utils.dart +++ b/lib/utils/page_utils.dart @@ -330,17 +330,21 @@ class PageUtils { ); } - static void enterPip(Floating floating, int width, int height) { - Rational aspectRatio = Rational(width, height); - floating.enable( - EnableManual( - aspectRatio: aspectRatio.fitsInAndroidRequirements - ? aspectRatio - : height > width - ? const Rational.vertical() - : const Rational.landscape(), - ), - ); + static void enterPip({int? width, int? height}) { + if (width != null && height != null) { + Rational aspectRatio = Rational(width, height); + Floating().enable( + EnableManual( + aspectRatio: aspectRatio.fitsInAndroidRequirements + ? aspectRatio + : height > width + ? const Rational.vertical() + : const Rational.landscape(), + ), + ); + } else { + Floating().enable(const EnableManual()); + } } static Future pushDynDetail(DynamicItemModel item, floor, diff --git a/pubspec.lock b/pubspec.lock index d7cf81b10..061ea9a02 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -607,7 +607,7 @@ packages: description: path: "." ref: version-3 - resolved-ref: "44bd7a589f199e0b8f7f5bb1a6df08579079c570" + resolved-ref: "929e9ec1312d9d1b4755d7589dd53db5b4d6d50d" url: "https://github.com/bggRGjQaUbCoE/floating.git" source: git version: "3.0.0"