mod: 详情页横屏布局(bug很多不要下载!)

This commit is contained in:
orz12
2024-02-08 23:29:42 +08:00
parent 88bc9e3ff9
commit 2ed7d00483
17 changed files with 294 additions and 102 deletions

View File

@@ -31,6 +31,7 @@ Box localCache = GStrorage.localCache;
class PlPlayerController {
Player? _videoPlayerController;
VideoController? _videoController;
void Function({bool? status})? triggerFullscreenCallback;
// 添加一个私有静态变量来保存实例
static PlPlayerController? _instance;
@@ -232,6 +233,11 @@ class PlPlayerController {
// 播放顺序相关
PlayRepeat playRepeat = PlayRepeat.pause;
void setTriggerFullscreenCallback(
void Function({bool? status}) triggerFullscreenCallback) {
this.triggerFullscreenCallback = triggerFullscreenCallback;
}
void updateSliderPositionSecond() {
int newSecond = _sliderPosition.value.inSeconds;
if (sliderPositionSeconds.value != newSecond) {
@@ -1001,6 +1007,9 @@ class PlPlayerController {
}
toggleFullScreen(false);
}
if (triggerFullscreenCallback != null) {
triggerFullscreenCallback!(status: status);
}
}
void addPositionListener(Function(Duration position) listener) =>

View File

@@ -48,6 +48,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late VideoController videoController;
final PLVideoPlayerController _ctr = Get.put(PLVideoPlayerController());
final GlobalKey _playerKey = GlobalKey();
// bool _mountSeekBackwardButton = false;
// bool _mountSeekForwardButton = false;
// bool _hideSeekBackwardButton = false;
@@ -72,7 +73,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late int defaultBtmProgressBehavior;
late bool enableQuickDouble;
late bool enableBackgroundPlay;
late double screenWidth;
// 用于记录上一次全屏切换手势触发时间,避免误触
DateTime? lastFullScreenToggleTime;
@@ -116,7 +116,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
@override
void initState() {
super.initState();
screenWidth = Get.size.width;
animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 300));
videoController = widget.controller.videoController!;
@@ -210,6 +209,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
);
return Stack(
fit: StackFit.passthrough,
key: _playerKey,
children: <Widget>[
Obx(
() => Video(
@@ -445,7 +445,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
if (_.videoType.value == 'live' || _.controlsLock.value) {
return;
}
final double totalWidth = MediaQuery.sizeOf(context).width;
RenderBox renderBox = _playerKey.currentContext!.findRenderObject() as RenderBox;
final double totalWidth = renderBox.size.width;
final double tapPosition = details.localPosition.dx;
final double sectionWidth = totalWidth / 3;
String type = 'left';
@@ -475,7 +476,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
// final double tapPosition = details.localPosition.dx;
final int curSliderPosition =
_.sliderPosition.value.inMilliseconds;
final double scale = 90000 / MediaQuery.sizeOf(context).width;
RenderBox renderBox = _playerKey.currentContext!.findRenderObject() as RenderBox;
final double scale = 90000 / renderBox.size.width;
final Duration pos = Duration(
milliseconds:
curSliderPosition + (details.delta.dx * scale).round());
@@ -494,7 +496,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
},
// 垂直方向 音量/亮度调节
onVerticalDragUpdate: (DragUpdateDetails details) async {
final double totalWidth = MediaQuery.sizeOf(context).width;
RenderBox renderBox = _playerKey.currentContext!.findRenderObject() as RenderBox;
final double totalWidth = renderBox.size.width;
final double tapPosition = details.localPosition.dx;
final double sectionWidth = totalWidth / 3;
final double delta = details.delta.dy;
@@ -510,10 +513,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
}
if (tapPosition < sectionWidth) {
// 左边区域 👈
final double level = (_.isFullScreen.value
? Get.size.height
: screenWidth * 9 / 16) *
3;
final double level = renderBox.size.height * 3;
final double brightness =
_ctr.brightnessValue.value - delta / level;
final double result = brightness.clamp(0.0, 1.0);
@@ -540,10 +540,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_distance = dy;
} else {
// 右边区域 👈
final double level = (_.isFullScreen.value
? Get.size.height
: screenWidth * 9 / 16) *
0.5;
final double level = renderBox.size.height * 0.5;
if(lastVolume < 0) {
lastVolume = _ctr.volumeValue.value;
}
@@ -761,11 +758,12 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
)
: nil,
),
Expanded(
child: SizedBox(
width: MediaQuery.sizeOf(context).width / 4,
),
),
const Spacer(),
// Expanded(
// child: SizedBox(
// width: context.width / 4,
// ),
// ),
Expanded(
child: _ctr.mountSeekForwardButton.value
? TweenAnimationBuilder<double>(

View File

@@ -146,7 +146,7 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget {
size: 15,
color: Colors.white,
),
fuc: () => triggerFullScreen!(),
fuc: () => triggerFullScreen!(status: !_.isFullScreen.value),
),
),
],