Closes #1680

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-10-24 12:12:56 +08:00
parent bbcf0dec1b
commit 4256c2b023
5 changed files with 98 additions and 149 deletions

View File

@@ -33,7 +33,6 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:canvas_danmaku/canvas_danmaku.dart'; import 'package:canvas_danmaku/canvas_danmaku.dart';
import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show SystemUiOverlayStyle;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart' hide ContextExtensionss; import 'package:get/get.dart' hide ContextExtensionss;
import 'package:screen_brightness_platform_interface/screen_brightness_platform_interface.dart'; import 'package:screen_brightness_platform_interface/screen_brightness_platform_interface.dart';
@@ -351,38 +350,16 @@ class _LiveRoomPageState extends State<LiveRoomPage>
); );
} }
SystemUiOverlayStyle _systemOverlayStyleForBrightness(
Brightness brightness, [
Color? backgroundColor,
]) {
final SystemUiOverlayStyle style = brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark;
// For backward compatibility, create an overlay style without system navigation bar settings.
return SystemUiOverlayStyle(
statusBarColor: backgroundColor,
statusBarBrightness: style.statusBarBrightness,
statusBarIconBrightness: style.statusBarIconBrightness,
systemStatusBarContrastEnforced: style.systemStatusBarContrastEnforced,
);
}
Widget get childWhenDisabled { Widget get childWhenDisabled {
return AnnotatedRegion<SystemUiOverlayStyle>( return Obx(() {
value: _systemOverlayStyleForBrightness( final isFullScreen = this.isFullScreen;
Brightness.dark, return Stack(
Theme.of(context).useMaterial3 ? const Color(0x00000000) : null,
),
child: ColoredBox(
color: Colors.black,
child: Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
const SizedBox.expand(child: ColoredBox(color: Colors.black)),
if (!isFullScreen)
Obx( Obx(
() { () {
if (isFullScreen) {
return const SizedBox.shrink();
}
final appBackground = _liveRoomController final appBackground = _liveRoomController
.roomInfoH5 .roomInfoH5
.value .value
@@ -407,34 +384,31 @@ class _LiveRoomPageState extends State<LiveRoomPage>
); );
}, },
), ),
if (isPortrait) Scaffold(
Obx( backgroundColor: Colors.transparent,
appBar: _buildAppBar(isFullScreen),
body: isPortrait
? Obx(
() { () {
if (_liveRoomController.isPortrait.value) { if (_liveRoomController.isPortrait.value) {
return _buildPP; return _buildPP(isFullScreen);
} }
return _buildPH; return _buildPH(isFullScreen);
}, },
) )
else : _buildBodyH(isFullScreen),
_buildBodyH, ),
], ],
),
),
); );
});
} }
Widget get _buildPH { Widget _buildPH(bool isFullScreen) {
final isFullScreen = this.isFullScreen;
final height = maxWidth * 9 / 16; final height = maxWidth * 9 / 16;
final videoHeight = isFullScreen ? maxHeight : height; final videoHeight = isFullScreen ? maxHeight - padding.top : height;
final bottomHeight = maxHeight - padding.top - height - kToolbarHeight; final bottomHeight = maxHeight - padding.top - height - kToolbarHeight;
return Column( return Column(
children: [ children: [
Offstage(
offstage: isFullScreen,
child: _buildAppBar,
),
SizedBox( SizedBox(
width: maxWidth, width: maxWidth,
height: videoHeight, height: videoHeight,
@@ -456,18 +430,15 @@ class _LiveRoomPageState extends State<LiveRoomPage>
); );
} }
Widget get _buildPP { Widget _buildPP(bool isFullScreen) {
final isFullScreen = this.isFullScreen;
final bottomHeight = 70 + padding.bottom; final bottomHeight = 70 + padding.bottom;
final topPadding = padding.top + kToolbarHeight;
final videoHeight = isFullScreen final videoHeight = isFullScreen
? maxHeight - padding.top ? maxHeight - padding.top
: maxHeight - bottomHeight - topPadding; : maxHeight - bottomHeight;
return Stack( return Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
Positioned.fill( Positioned.fill(
top: isFullScreen ? padding.top : topPadding,
bottom: isFullScreen ? 0 : bottomHeight, bottom: isFullScreen ? 0 : bottomHeight,
child: videoPlayerPanel( child: videoPlayerPanel(
width: maxWidth, width: maxWidth,
@@ -477,15 +448,6 @@ class _LiveRoomPageState extends State<LiveRoomPage>
alignment: isFullScreen ? Alignment.center : Alignment.topCenter, alignment: isFullScreen ? Alignment.center : Alignment.topCenter,
), ),
), ),
Positioned(
top: 0,
left: 0,
right: 0,
child: Offstage(
offstage: isFullScreen,
child: _buildAppBar,
),
),
Positioned( Positioned(
left: 0, left: 0,
right: 0, right: 0,
@@ -514,9 +476,10 @@ class _LiveRoomPageState extends State<LiveRoomPage>
); );
} }
PreferredSizeWidget get _buildAppBar { PreferredSizeWidget _buildAppBar(bool isFullScreen) {
final color = Theme.of(context).colorScheme.onSurfaceVariant; final color = Theme.of(context).colorScheme.onSurfaceVariant;
return AppBar( return AppBar(
toolbarHeight: isFullScreen ? 0 : null,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
foregroundColor: Colors.white, foregroundColor: Colors.white,
titleTextStyle: const TextStyle(color: Colors.white), titleTextStyle: const TextStyle(color: Colors.white),
@@ -677,34 +640,24 @@ class _LiveRoomPageState extends State<LiveRoomPage>
); );
} }
Widget get _buildBodyH { Widget _buildBodyH(bool isFullScreen) {
double videoWidth = double videoWidth =
clampDouble(maxHeight / maxWidth * 1.08, 0.56, 0.7) * maxWidth; clampDouble(maxHeight / maxWidth * 1.08, 0.56, 0.7) * maxWidth;
final rigthWidth = min(400.0, maxWidth - videoWidth - padding.horizontal); final rigthWidth = min(400.0, maxWidth - videoWidth - padding.horizontal);
videoWidth = maxWidth - rigthWidth; videoWidth = maxWidth - rigthWidth - padding.horizontal;
final videoHeight = maxHeight - padding.top; final videoHeight = maxHeight - padding.top;
return Obx(
() {
final isFullScreen = this.isFullScreen;
final width = isFullScreen ? maxWidth : videoWidth; final width = isFullScreen ? maxWidth : videoWidth;
final height = isFullScreen ? maxHeight : videoHeight; final height = isFullScreen ? maxHeight - padding.top : videoHeight;
return Column( return Padding(
children: [
Offstage(
offstage: isFullScreen,
child: _buildAppBar,
),
Expanded(
child: Padding(
padding: isFullScreen padding: isFullScreen
? EdgeInsets.zero ? EdgeInsets.zero
: EdgeInsets.only(left: padding.left, right: padding.right), : EdgeInsets.only(left: padding.left, right: padding.right),
child: Row( child: Row(
children: [ children: [
Container( Container(
margin: EdgeInsets.only(bottom: padding.bottom),
width: width, width: width,
height: height, height: height,
margin: EdgeInsets.only(bottom: padding.bottom),
child: videoPlayerPanel( child: videoPlayerPanel(
isFullScreen, isFullScreen,
fill: Colors.transparent, fill: Colors.transparent,
@@ -722,11 +675,6 @@ class _LiveRoomPageState extends State<LiveRoomPage>
), ),
], ],
), ),
),
),
],
);
},
); );
} }

View File

@@ -181,7 +181,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
if (!(mode == FullScreenMode.vertical || if (!(mode == FullScreenMode.vertical ||
(mode == FullScreenMode.auto && isVertical) || (mode == FullScreenMode.auto && isVertical) ||
(mode == FullScreenMode.ratio && (mode == FullScreenMode.ratio &&
(isVertical || maxHeight / maxWidth < 1.25)))) { (isVertical || maxHeight / maxWidth < kScreenRatio)))) {
landscape(); landscape();
} }
}); });
@@ -581,9 +581,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
if (shouldShow) if (shouldShow)
AppBar( AppBar(
backgroundColor: themeData.colorScheme.surface backgroundColor: themeData.colorScheme.surface
.withValues( .withValues(alpha: scrollRatio),
alpha: scrollRatio,
),
toolbarHeight: 0, toolbarHeight: 0,
systemOverlayStyle: Platform.isAndroid systemOverlayStyle: Platform.isAndroid
? SystemUiOverlayStyle( ? SystemUiOverlayStyle(
@@ -605,7 +603,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
onlyOneScrollInBody: true, onlyOneScrollInBody: true,
pinnedHeaderSliverHeightBuilder: () { pinnedHeaderSliverHeightBuilder: () {
double pinnedHeight = this.isFullScreen || !isPortrait double pinnedHeight = this.isFullScreen || !isPortrait
? maxHeight - (isPortrait ? padding.top : 0) ? maxHeight - padding.top
: videoDetailController.isExpanding || : videoDetailController.isExpanding ||
videoDetailController.isCollapsing videoDetailController.isCollapsing
? animHeight ? animHeight
@@ -632,7 +630,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
}, },
headerSliverBuilder: (context, innerBoxIsScrolled) { headerSliverBuilder: (context, innerBoxIsScrolled) {
final height = isFullScreen || !isPortrait final height = isFullScreen || !isPortrait
? maxHeight - (isPortrait ? padding.top : 0) ? maxHeight - padding.top
: videoDetailController.isExpanding || : videoDetailController.isExpanding ||
videoDetailController.isCollapsing videoDetailController.isCollapsing
? animHeight ? animHeight
@@ -875,13 +873,10 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
final isFullScreen = this.isFullScreen; final isFullScreen = this.isFullScreen;
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
appBar: isFullScreen appBar: AppBar(backgroundColor: Colors.black, toolbarHeight: 0),
? null
: AppBar(backgroundColor: Colors.black, toolbarHeight: 0),
extendBodyBehindAppBar: true,
body: Padding( body: Padding(
padding: !isFullScreen padding: !isFullScreen
? padding.copyWith(bottom: 0) ? padding.copyWith(top: 0, bottom: 0)
: EdgeInsets.zero, : EdgeInsets.zero,
child: childWhenDisabledLandscapeInner(isFullScreen, padding), child: childWhenDisabledLandscapeInner(isFullScreen, padding),
), ),
@@ -893,6 +888,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
final double videoHeight = maxHeight - padding.vertical; final double videoHeight = maxHeight - padding.vertical;
final double width = videoHeight * ratio; final double width = videoHeight * ratio;
final videoWidth = isFullScreen ? maxWidth : width; final videoWidth = isFullScreen ? maxWidth : width;
final introWidth = maxWidth - width - padding.horizontal;
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -907,7 +903,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
Offstage( Offstage(
offstage: isFullScreen, offstage: isFullScreen,
child: SizedBox( child: SizedBox(
width: maxWidth - width - padding.horizontal, width: introWidth,
height: maxHeight - padding.top, height: maxHeight - padding.top,
child: Scaffold( child: Scaffold(
key: videoDetailController.childKey, key: videoDetailController.childKey,
@@ -922,7 +918,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
controller: videoDetailController.tabCtr, controller: videoDetailController.tabCtr,
children: [ children: [
videoIntro( videoIntro(
width: maxWidth - width, width: introWidth,
height: maxHeight, height: maxHeight,
), ),
if (videoDetailController.showReply) videoReplyPanel(), if (videoDetailController.showReply) videoReplyPanel(),
@@ -1010,7 +1006,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
} }
final videoWidth = isFullScreen ? maxWidth : width; final videoWidth = isFullScreen ? maxWidth : width;
final double height = width * 9 / 16; final double height = width * 9 / 16;
final videoHeight = isFullScreen ? maxHeight : height; final videoHeight = isFullScreen ? maxHeight - padding.top : height;
if (height > maxHeight) { if (height > maxHeight) {
return childSplit(16 / 9); return childSplit(16 / 9);
} }
@@ -1101,12 +1097,11 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
final isFullScreen = this.isFullScreen; final isFullScreen = this.isFullScreen;
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
appBar: isFullScreen appBar: AppBar(backgroundColor: Colors.black, toolbarHeight: 0),
? null
: AppBar(backgroundColor: Colors.black, toolbarHeight: 0),
extendBodyBehindAppBar: true,
body: Padding( body: Padding(
padding: !isFullScreen ? padding.copyWith(bottom: 0) : EdgeInsets.zero, padding: !isFullScreen
? padding.copyWith(top: 0, bottom: 0)
: EdgeInsets.zero,
child: childWhenDisabledAlmostSquareInner(isFullScreen, padding), child: childWhenDisabledAlmostSquareInner(isFullScreen, padding),
), ),
); );
@@ -1125,7 +1120,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
} }
final shouldShowSeasonPanel = _shouldShowSeasonPanel; final shouldShowSeasonPanel = _shouldShowSeasonPanel;
final double height = maxHeight / 2.5; final double height = maxHeight / 2.5;
final videoHeight = isFullScreen ? maxHeight : height; final videoHeight = isFullScreen ? maxHeight - padding.top : height;
final bottomHeight = maxHeight - height - padding.top; final bottomHeight = maxHeight - height - padding.top;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -1376,7 +1371,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
child = plPlayer(width: maxWidth, height: maxHeight, isPipMode: true); child = plPlayer(width: maxWidth, height: maxHeight, isPipMode: true);
} else if (!videoDetailController.horizontalScreen) { } else if (!videoDetailController.horizontalScreen) {
child = childWhenDisabled; child = childWhenDisabled;
} else if (maxWidth > maxHeight * 1.25) { } else if (maxWidth > maxHeight * kScreenRatio) {
child = childWhenDisabledLandscape; child = childWhenDisabledLandscape;
} else if (maxWidth * (9 / 16) < (2 / 5) * maxHeight) { } else if (maxWidth * (9 / 16) < (2 / 5) * maxHeight) {
child = childWhenDisabled; child = childWhenDisabled;
@@ -1748,7 +1743,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
showEpisodes: showEpisodes, showEpisodes: showEpisodes,
onShowMemberPage: onShowMemberPage, onShowMemberPage: onShowMemberPage,
isPortrait: isPortrait, isPortrait: isPortrait,
isHorizontal: isHorizontal ?? width! > height! * 1.25, isHorizontal: isHorizontal ?? width! > height! * kScreenRatio,
), ),
if (needRelated && if (needRelated &&
videoDetailController videoDetailController

View File

@@ -1256,7 +1256,9 @@ class PlPlayerController {
} }
await _videoPlayerController?.setRate(speed); await _videoPlayerController?.setRate(speed);
_playbackSpeed.value = speed;
if (danmakuController != null) { if (danmakuController != null) {
try {
DanmakuOption currentOption = danmakuController!.option; DanmakuOption currentOption = danmakuController!.option;
double defaultDuration = currentOption.duration * lastPlaybackSpeed; double defaultDuration = currentOption.duration * lastPlaybackSpeed;
double defaultStaticDuration = double defaultStaticDuration =
@@ -1266,8 +1268,8 @@ class PlPlayerController {
staticDuration: defaultStaticDuration / speed, staticDuration: defaultStaticDuration / speed,
); );
danmakuController!.updateOption(updatedOption); danmakuController!.updateOption(updatedOption);
} catch (_) {}
} }
_playbackSpeed.value = speed;
} }
// 还原默认速度 // 还原默认速度
@@ -1591,7 +1593,7 @@ class PlPlayerController {
if ((mode == FullScreenMode.vertical || if ((mode == FullScreenMode.vertical ||
(mode == FullScreenMode.auto && isVertical) || (mode == FullScreenMode.auto && isVertical) ||
(mode == FullScreenMode.ratio && (mode == FullScreenMode.ratio &&
(isVertical || size.height / size.width < 1.25)))) { (isVertical || size.height / size.width < kScreenRatio)))) {
await verticalScreenForTwoSeconds(); await verticalScreenForTwoSeconds();
} else { } else {
await landscape(); await landscape();
@@ -1740,10 +1742,10 @@ class PlPlayerController {
} }
return; return;
} }
_playerCount = 0;
disableAutoEnterPip(); disableAutoEnterPip();
setPlayCallBack(null); setPlayCallBack(null);
dmState.clear(); dmState.clear();
_playerCount = 0;
_clearPreview(); _clearPreview();
Utils.channel.setMethodCallHandler(null); Utils.channel.setMethodCallHandler(null);
_timer?.cancel(); _timer?.cancel();

View File

@@ -1,3 +1,5 @@
const double kScreenRatio = 1.2;
// 全屏模式 // 全屏模式
enum FullScreenMode { enum FullScreenMode {
// 根据内容自适应 // 根据内容自适应
@@ -8,8 +10,8 @@ enum FullScreenMode {
vertical('强制竖屏'), vertical('强制竖屏'),
// 始终横屏 // 始终横屏
horizontal('强制横屏'), horizontal('强制横屏'),
// 屏幕长宽比<1.25或为竖屏视频时竖屏,否则横屏 // 屏幕长宽比 < kScreenRatio 或为竖屏视频时竖屏,否则横屏
ratio('屏幕长宽比<1.25或为竖屏视频时竖屏,否则横屏'), ratio('屏幕长宽比<$kScreenRatio或为竖屏视频时竖屏,否则横屏'),
// 强制重力转屏(仅安卓) // 强制重力转屏(仅安卓)
gravity('忽略系统方向锁定,强制按重力转屏(仅安卓)'); gravity('忽略系统方向锁定,强制按重力转屏(仅安卓)');

View File

@@ -1185,7 +1185,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
) )
..onLongPressStart = ((_) => ..onLongPressStart = ((_) =>
plPlayerController.setLongPressStatus(true)) plPlayerController.setLongPressStatus(true))
..onLongPressEnd = (_) => plPlayerController.setLongPressStatus(false); ..onLongPressEnd = ((_) => plPlayerController.setLongPressStatus(false))
..onLongPressCancel = (() =>
plPlayerController.setLongPressStatus(false));
late final OneSequenceGestureRecognizer _tapGestureRecognizer; late final OneSequenceGestureRecognizer _tapGestureRecognizer;
late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer; late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer;
StreamSubscription<bool>? _danmakuListener; StreamSubscription<bool>? _danmakuListener;