Merge pull request #311 from orz12/fix_orientation
重构全屏逻辑,修复全屏弹幕与横屏错位问题
This commit is contained in:
@ -95,9 +95,9 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
|||||||
// 根据position判断是否有已缓存弹幕。没有则请求对应段
|
// 根据position判断是否有已缓存弹幕。没有则请求对应段
|
||||||
int segIndex = (currentPosition / (6 * 60 * 1000)).ceil();
|
int segIndex = (currentPosition / (6 * 60 * 1000)).ceil();
|
||||||
segIndex = segIndex < 1 ? 1 : segIndex;
|
segIndex = segIndex < 1 ? 1 : segIndex;
|
||||||
print('🌹🌹: ${segIndex}');
|
// print('🌹🌹: ${segIndex}');
|
||||||
print('🌹🌹: ${ctr.dmSegList.length}');
|
// print('🌹🌹: ${ctr.dmSegList.length}');
|
||||||
print('🌹🌹: ${ctr.hasrequestSeg.contains(segIndex - 1)}');
|
// print('🌹🌹: ${ctr.hasrequestSeg.contains(segIndex - 1)}');
|
||||||
if (segIndex - 1 >= ctr.dmSegList.length ||
|
if (segIndex - 1 >= ctr.dmSegList.length ||
|
||||||
(ctr.dmSegList[segIndex - 1].elems.isEmpty &&
|
(ctr.dmSegList[segIndex - 1].elems.isEmpty &&
|
||||||
!ctr.hasrequestSeg.contains(segIndex - 1))) {
|
!ctr.hasrequestSeg.contains(segIndex - 1))) {
|
||||||
|
@ -138,8 +138,8 @@ class VideoDetailController extends GetxController
|
|||||||
}
|
}
|
||||||
|
|
||||||
showReplyReplyPanel() {
|
showReplyReplyPanel() {
|
||||||
PersistentBottomSheetController<void>? ctr =
|
PersistentBottomSheetController? ctr =
|
||||||
scaffoldKey.currentState?.showBottomSheet<void>((BuildContext context) {
|
scaffoldKey.currentState?.showBottomSheet((BuildContext context) {
|
||||||
return VideoReplyReplyPanel(
|
return VideoReplyReplyPanel(
|
||||||
oid: oid,
|
oid: oid,
|
||||||
rpid: fRpid,
|
rpid: fRpid,
|
||||||
|
@ -21,6 +21,7 @@ import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
|
|||||||
import 'package:pilipala/services/service_locator.dart';
|
import 'package:pilipala/services/service_locator.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
|
import 'package:pilipala/plugin/pl_player/utils/fullscreen.dart';
|
||||||
import 'widgets/header_control.dart';
|
import 'widgets/header_control.dart';
|
||||||
|
|
||||||
class VideoDetailPage extends StatefulWidget {
|
class VideoDetailPage extends StatefulWidget {
|
||||||
@ -235,9 +236,17 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
final videoHeight = MediaQuery.of(context).size.width * 9 / 16;
|
final videoHeight = MediaQuery.of(context).size.width * 9 / 16;
|
||||||
final double pinnedHeaderHeight =
|
final double pinnedHeaderHeight =
|
||||||
statusBarHeight + kToolbarHeight + videoHeight;
|
statusBarHeight + kToolbarHeight + videoHeight;
|
||||||
|
if (MediaQuery.of(context).orientation == Orientation.landscape ||
|
||||||
|
plPlayerController!.isFullScreen.value) {
|
||||||
|
enterFullScreen();
|
||||||
|
} else {
|
||||||
|
exitFullScreen();
|
||||||
|
}
|
||||||
Widget childWhenDisabled = SafeArea(
|
Widget childWhenDisabled = SafeArea(
|
||||||
top: false,
|
top: MediaQuery.of(context).orientation == Orientation.portrait,
|
||||||
bottom: false,
|
bottom: MediaQuery.of(context).orientation == Orientation.portrait,
|
||||||
|
left: !plPlayerController!.isFullScreen.value,
|
||||||
|
right: !plPlayerController!.isFullScreen.value,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
Scaffold(
|
Scaffold(
|
||||||
@ -249,145 +258,171 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
headerSliverBuilder:
|
headerSliverBuilder:
|
||||||
(BuildContext context, bool innerBoxIsScrolled) {
|
(BuildContext context, bool innerBoxIsScrolled) {
|
||||||
return <Widget>[
|
return <Widget>[
|
||||||
SliverAppBar(
|
Obx(() => PopScope(
|
||||||
automaticallyImplyLeading: false,
|
canPop: !plPlayerController!.isFullScreen.value,
|
||||||
pinned: false,
|
onPopInvoked: (bool didPop) {
|
||||||
elevation: 0,
|
if (plPlayerController!.isFullScreen.value) {
|
||||||
scrolledUnderElevation: 0,
|
plPlayerController!
|
||||||
forceElevated: innerBoxIsScrolled,
|
.triggerFullScreen(status: false);
|
||||||
expandedHeight: videoHeight,
|
}
|
||||||
backgroundColor: Colors.black,
|
if (MediaQuery.of(context).orientation ==
|
||||||
flexibleSpace: FlexibleSpaceBar(
|
Orientation.landscape) {
|
||||||
background: Padding(
|
verticalScreen();
|
||||||
padding: EdgeInsets.only(top: statusBarHeight),
|
}
|
||||||
child: LayoutBuilder(
|
},
|
||||||
builder: (context, boxConstraints) {
|
child: SliverAppBar(
|
||||||
double maxWidth = boxConstraints.maxWidth;
|
automaticallyImplyLeading: false,
|
||||||
double maxHeight = boxConstraints.maxHeight;
|
pinned: false,
|
||||||
return Stack(
|
elevation: 0,
|
||||||
children: [
|
scrolledUnderElevation: 0,
|
||||||
FutureBuilder(
|
forceElevated: innerBoxIsScrolled,
|
||||||
future: _futureBuilderFuture,
|
expandedHeight:
|
||||||
builder: ((context, snapshot) {
|
plPlayerController!.isFullScreen.value ||
|
||||||
if (snapshot.hasData &&
|
MediaQuery.of(context).orientation ==
|
||||||
snapshot.data['status']) {
|
Orientation.landscape
|
||||||
return Obx(
|
? MediaQuery.of(context).size.height -
|
||||||
() => !videoDetailController
|
(MediaQuery.of(context).orientation ==
|
||||||
.autoPlay.value
|
Orientation.landscape
|
||||||
? const SizedBox()
|
? 0
|
||||||
: PLVideoPlayer(
|
: statusBarHeight)
|
||||||
controller: plPlayerController!,
|
: videoHeight,
|
||||||
headerControl:
|
backgroundColor: Colors.black,
|
||||||
videoDetailController
|
flexibleSpace: FlexibleSpaceBar(
|
||||||
.headerControl,
|
background: LayoutBuilder(
|
||||||
danmuWidget: Obx(
|
builder: (context, boxConstraints) {
|
||||||
() => PlDanmaku(
|
double maxWidth = boxConstraints.maxWidth;
|
||||||
key: Key(
|
double maxHeight = boxConstraints.maxHeight;
|
||||||
videoDetailController
|
return Stack(
|
||||||
.danmakuCid.value
|
children: [
|
||||||
.toString()),
|
FutureBuilder(
|
||||||
cid: videoDetailController
|
future: _futureBuilderFuture,
|
||||||
.danmakuCid.value,
|
builder: ((context, snapshot) {
|
||||||
playerController:
|
if (snapshot.hasData &&
|
||||||
plPlayerController!,
|
snapshot.data['status']) {
|
||||||
),
|
return Obx(
|
||||||
),
|
() => !videoDetailController
|
||||||
),
|
.autoPlay.value
|
||||||
);
|
? const SizedBox()
|
||||||
} else {
|
: PLVideoPlayer(
|
||||||
return const SizedBox();
|
controller:
|
||||||
}
|
plPlayerController!,
|
||||||
}),
|
headerControl:
|
||||||
),
|
videoDetailController
|
||||||
|
.headerControl,
|
||||||
Obx(
|
danmuWidget: Obx(
|
||||||
() => Visibility(
|
() => PlDanmaku(
|
||||||
visible:
|
key: Key(
|
||||||
videoDetailController.isShowCover.value,
|
videoDetailController
|
||||||
child: Positioned(
|
.danmakuCid
|
||||||
top: 0,
|
.value
|
||||||
left: 0,
|
.toString()),
|
||||||
right: 0,
|
cid:
|
||||||
child: NetworkImgLayer(
|
videoDetailController
|
||||||
type: 'emote',
|
.danmakuCid
|
||||||
src: videoDetailController
|
.value,
|
||||||
.videoItem['pic'],
|
playerController:
|
||||||
width: maxWidth,
|
plPlayerController!,
|
||||||
height: maxHeight,
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
/// 关闭自动播放时 手动播放
|
Obx(
|
||||||
Obx(
|
() => Visibility(
|
||||||
() => Visibility(
|
visible: videoDetailController
|
||||||
visible: videoDetailController
|
.isShowCover.value,
|
||||||
.isShowCover.value &&
|
child: Positioned(
|
||||||
videoDetailController
|
|
||||||
.isEffective.value &&
|
|
||||||
!videoDetailController.autoPlay.value,
|
|
||||||
child: Stack(
|
|
||||||
children: [
|
|
||||||
Positioned(
|
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: AppBar(
|
child: NetworkImgLayer(
|
||||||
primary: false,
|
type: 'emote',
|
||||||
foregroundColor: Colors.white,
|
src: videoDetailController
|
||||||
backgroundColor:
|
.videoItem['pic'],
|
||||||
Colors.transparent,
|
width: maxWidth,
|
||||||
actions: [
|
height: maxHeight,
|
||||||
IconButton(
|
),
|
||||||
tooltip: '稍后再看',
|
),
|
||||||
onPressed: () async {
|
),
|
||||||
var res = await UserHttp
|
),
|
||||||
.toViewLater(
|
|
||||||
bvid:
|
/// 关闭自动播放时 手动播放
|
||||||
videoDetailController
|
Obx(
|
||||||
.bvid);
|
() => Visibility(
|
||||||
SmartDialog.showToast(
|
visible: videoDetailController
|
||||||
res['msg']);
|
.isShowCover.value &&
|
||||||
},
|
videoDetailController
|
||||||
icon: const Icon(
|
.isEffective.value &&
|
||||||
Icons.history_outlined),
|
!videoDetailController
|
||||||
|
.autoPlay.value,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: AppBar(
|
||||||
|
primary: false,
|
||||||
|
foregroundColor:
|
||||||
|
Colors.white,
|
||||||
|
backgroundColor:
|
||||||
|
Colors.transparent,
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
tooltip: '稍后再看',
|
||||||
|
onPressed: () async {
|
||||||
|
var res = await UserHttp
|
||||||
|
.toViewLater(
|
||||||
|
bvid:
|
||||||
|
videoDetailController
|
||||||
|
.bvid);
|
||||||
|
SmartDialog.showToast(
|
||||||
|
res['msg']);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons
|
||||||
|
.history_outlined),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 14)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
right: 12,
|
||||||
|
bottom: 10,
|
||||||
|
child: TextButton.icon(
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor:
|
||||||
|
MaterialStateProperty
|
||||||
|
.resolveWith(
|
||||||
|
(states) {
|
||||||
|
return Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primaryContainer;
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
onPressed: () =>
|
||||||
|
handlePlay(),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.play_circle_outline,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
label: const Text('Play'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 14)
|
|
||||||
],
|
],
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
Positioned(
|
],
|
||||||
right: 12,
|
);
|
||||||
bottom: 10,
|
},
|
||||||
child: TextButton.icon(
|
),
|
||||||
style: ButtonStyle(
|
)),
|
||||||
backgroundColor:
|
)),
|
||||||
MaterialStateProperty
|
|
||||||
.resolveWith((states) {
|
|
||||||
return Theme.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.primaryContainer;
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
onPressed: () => handlePlay(),
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.play_circle_outline,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
label: const Text('Play'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
// pinnedHeaderSliverHeightBuilder: () {
|
// pinnedHeaderSliverHeightBuilder: () {
|
||||||
|
@ -880,7 +880,18 @@ class _HeaderControlState extends State<HeaderControl> {
|
|||||||
size: 15,
|
size: 15,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
fuc: () => Get.back(),
|
fuc: () => {
|
||||||
|
if (widget.controller!.isFullScreen.value){
|
||||||
|
widget.controller!.triggerFullScreen(status: false)
|
||||||
|
} else {
|
||||||
|
if (MediaQuery.of(context).orientation == Orientation.landscape){
|
||||||
|
SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.portraitUp,
|
||||||
|
])
|
||||||
|
},
|
||||||
|
Get.back()
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SizedBox(width: buttonSpace),
|
SizedBox(width: buttonSpace),
|
||||||
ComBtn(
|
ComBtn(
|
||||||
|
@ -899,6 +899,7 @@ class PlPlayerController {
|
|||||||
await StatusBarControl.setHidden(true, animation: StatusBarAnimation.FADE);
|
await StatusBarControl.setHidden(true, animation: StatusBarAnimation.FADE);
|
||||||
if (!isFullScreen.value && status) {
|
if (!isFullScreen.value && status) {
|
||||||
/// 按照视频宽高比决定全屏方向
|
/// 按照视频宽高比决定全屏方向
|
||||||
|
toggleFullScreen(true);
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case FullScreenMode.auto:
|
case FullScreenMode.auto:
|
||||||
if (direction.value == 'horizontal') {
|
if (direction.value == 'horizontal') {
|
||||||
@ -927,41 +928,40 @@ class PlPlayerController {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFullScreen(true);
|
// bool isValid =
|
||||||
bool isValid =
|
// direction.value == 'vertical' || mode == FullScreenMode.vertical
|
||||||
direction.value == 'vertical' || mode == FullScreenMode.vertical
|
// ? true
|
||||||
? true
|
// : false;
|
||||||
: false;
|
// var result = await showDialog(
|
||||||
var result = await showDialog(
|
// context: Get.context!,
|
||||||
context: Get.context!,
|
// useSafeArea: false,
|
||||||
useSafeArea: false,
|
// builder: (context) => Dialog.fullscreen(
|
||||||
builder: (context) => Dialog.fullscreen(
|
// backgroundColor: Colors.black,
|
||||||
backgroundColor: Colors.black,
|
// child: SafeArea(
|
||||||
child: SafeArea(
|
// // 忽略手机安全区域
|
||||||
// 忽略手机安全区域
|
// top: isValid,
|
||||||
top: isValid,
|
// left: false,
|
||||||
left: false,
|
// right: false,
|
||||||
right: false,
|
// bottom: isValid,
|
||||||
bottom: isValid,
|
// child: PLVideoPlayer(
|
||||||
child: PLVideoPlayer(
|
// controller: this,
|
||||||
controller: this,
|
// headerControl: headerControl,
|
||||||
headerControl: headerControl,
|
// bottomControl: bottomControl,
|
||||||
bottomControl: bottomControl,
|
// danmuWidget: danmuWidget,
|
||||||
danmuWidget: danmuWidget,
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// );
|
||||||
);
|
// if (result == null) {
|
||||||
if (result == null) {
|
// // 退出全屏
|
||||||
// 退出全屏
|
// StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
|
||||||
StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
|
// exitFullScreen();
|
||||||
exitFullScreen();
|
// await verticalScreen();
|
||||||
await verticalScreen();
|
// toggleFullScreen(false);
|
||||||
toggleFullScreen(false);
|
// }
|
||||||
}
|
|
||||||
} else if (isFullScreen.value) {
|
} else if (isFullScreen.value) {
|
||||||
StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
|
StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
|
||||||
Get.back();
|
// Get.back();
|
||||||
exitFullScreen();
|
exitFullScreen();
|
||||||
await verticalScreen();
|
await verticalScreen();
|
||||||
toggleFullScreen(false);
|
toggleFullScreen(false);
|
||||||
|
@ -25,6 +25,7 @@ import 'widgets/backward_seek.dart';
|
|||||||
import 'widgets/bottom_control.dart';
|
import 'widgets/bottom_control.dart';
|
||||||
import 'widgets/common_btn.dart';
|
import 'widgets/common_btn.dart';
|
||||||
import 'widgets/forward_seek.dart';
|
import 'widgets/forward_seek.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
|
||||||
class PLVideoPlayer extends StatefulWidget {
|
class PLVideoPlayer extends StatefulWidget {
|
||||||
final PlPlayerController controller;
|
final PlPlayerController controller;
|
||||||
@ -76,6 +77,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
late bool enableBackgroundPlay;
|
late bool enableBackgroundPlay;
|
||||||
late double screenWidth;
|
late double screenWidth;
|
||||||
|
|
||||||
|
// 用于记录上一次全屏切换手势触发时间,避免误触
|
||||||
|
DateTime? lastFullScreenToggleTime;
|
||||||
|
|
||||||
void onDoubleTapSeekBackward() {
|
void onDoubleTapSeekBackward() {
|
||||||
_ctr.onDoubleTapSeekBackward();
|
_ctr.onDoubleTapSeekBackward();
|
||||||
}
|
}
|
||||||
@ -503,11 +507,15 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
final tapPosition = details.localPosition.dx;
|
final tapPosition = details.localPosition.dx;
|
||||||
final sectionWidth = totalWidth / 3;
|
final sectionWidth = totalWidth / 3;
|
||||||
final delta = details.delta.dy;
|
final delta = details.delta.dy;
|
||||||
|
|
||||||
/// 锁定时禁用
|
/// 锁定时禁用
|
||||||
if (_.controlsLock.value) {
|
if (_.controlsLock.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (lastFullScreenToggleTime != null &&
|
||||||
|
DateTime.now().difference(lastFullScreenToggleTime!) <
|
||||||
|
const Duration(milliseconds: 500)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (tapPosition < sectionWidth) {
|
if (tapPosition < sectionWidth) {
|
||||||
// 左边区域 👈
|
// 左边区域 👈
|
||||||
double level = (_.isFullScreen.value
|
double level = (_.isFullScreen.value
|
||||||
@ -523,12 +531,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
const double threshold = 7.0; // 滑动阈值
|
const double threshold = 7.0; // 滑动阈值
|
||||||
if (dy > _distance && dy > threshold) {
|
if (dy > _distance && dy > threshold) {
|
||||||
if (_.isFullScreen.value) {
|
if (_.isFullScreen.value) {
|
||||||
|
lastFullScreenToggleTime = DateTime.now();
|
||||||
// 下滑退出全屏
|
// 下滑退出全屏
|
||||||
await widget.controller.triggerFullScreen(status: false);
|
await widget.controller.triggerFullScreen(status: false);
|
||||||
}
|
}
|
||||||
_distance = 0.0;
|
_distance = 0.0;
|
||||||
} else if (dy < _distance && dy < -threshold) {
|
} else if (dy < _distance && dy < -threshold) {
|
||||||
if (!_.isFullScreen.value) {
|
if (!_.isFullScreen.value) {
|
||||||
|
lastFullScreenToggleTime = DateTime.now();
|
||||||
// 上滑进入全屏
|
// 上滑进入全屏
|
||||||
await widget.controller.triggerFullScreen();
|
await widget.controller.triggerFullScreen();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user