Merge pull request #443 from orz12/opt-video-detail-page

fix: 播放页数个问题
This commit is contained in:
guozhigq
2024-01-31 08:06:26 +08:00
committed by GitHub
2 changed files with 182 additions and 183 deletions

View File

@ -4,7 +4,7 @@ import 'package:pilipala/http/video.dart';
class ReleatedController extends GetxController { class ReleatedController extends GetxController {
// 视频aid // 视频aid
String bvid = Get.parameters['bvid']!; String bvid = Get.parameters['bvid'] ?? "";
// 推荐视频列表 // 推荐视频列表
List relatedVideoList = []; List relatedVideoList = [];

View File

@ -61,6 +61,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
final Floating floating = Floating(); final Floating floating = Floating();
// 生命周期监听 // 生命周期监听
late final AppLifecycleListener _lifecycleListener; late final AppLifecycleListener _lifecycleListener;
bool isShowing = true;
@override @override
void initState() { void initState() {
@ -216,15 +217,15 @@ class _VideoDetailPageState extends State<VideoDetailPage>
videoIntroController.isPaused = true; videoIntroController.isPaused = true;
plPlayerController!.removeStatusLister(playerListener); plPlayerController!.removeStatusLister(playerListener);
plPlayerController!.pause(); plPlayerController!.pause();
plPlayerController!.danmakuController?.pause();
plPlayerController!.danmakuController?.clear();
} }
setState(() => isShowing = false);
super.didPushNext(); super.didPushNext();
} }
@override @override
// 返回当前页面时 // 返回当前页面时
void didPopNext() async { void didPopNext() async {
setState(() => isShowing = true);
videoDetailController.isFirstTime = false; videoDetailController.isFirstTime = false;
final bool autoplay = autoPlayEnable; final bool autoplay = autoPlayEnable;
videoDetailController.playerInit(autoplay: autoplay); videoDetailController.playerInit(autoplay: autoplay);
@ -280,19 +281,13 @@ class _VideoDetailPageState extends State<VideoDetailPage>
final double videoHeight = MediaQuery.sizeOf(context).width * 9 / 16; final double videoHeight = MediaQuery.sizeOf(context).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 == true) {
enterFullScreen();
} else {
exitFullScreen();
}
Widget childWhenDisabled = SafeArea( Widget childWhenDisabled = SafeArea(
top: MediaQuery.of(context).orientation == Orientation.portrait && top: MediaQuery.of(context).orientation == Orientation.portrait &&
plPlayerController?.isFullScreen.value == true, plPlayerController?.isFullScreen.value == true,
bottom: MediaQuery.of(context).orientation == Orientation.portrait && bottom: MediaQuery.of(context).orientation == Orientation.portrait &&
plPlayerController?.isFullScreen.value == true, plPlayerController?.isFullScreen.value == true,
left: plPlayerController?.isFullScreen.value != true, left: false, //plPlayerController?.isFullScreen.value != true,
right: plPlayerController?.isFullScreen.value != true, right: false, //plPlayerController?.isFullScreen.value != true,
child: Stack( child: Stack(
children: [ children: [
Scaffold( Scaffold(
@ -309,187 +304,189 @@ class _VideoDetailPageState extends State<VideoDetailPage>
body: ExtendedNestedScrollView( body: ExtendedNestedScrollView(
controller: _extendNestCtr, controller: _extendNestCtr,
headerSliverBuilder: headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) { (BuildContext context2, bool innerBoxIsScrolled) {
return <Widget>[ return <Widget>[
Obx( Obx(
() => SliverAppBar( () {
automaticallyImplyLeading: false, if (MediaQuery.of(context).orientation ==
// 假装使用一个非空变量避免Obx检测不到而罢工 Orientation.landscape ||
pinned: videoDetailController.autoPlay.value ^ plPlayerController?.isFullScreen.value == true) {
false ^ enterFullScreen();
videoDetailController.autoPlay.value, } else {
elevation: 0, exitFullScreen();
scrolledUnderElevation: 0, }
forceElevated: innerBoxIsScrolled, return SliverAppBar(
expandedHeight: MediaQuery.of(context).orientation == automaticallyImplyLeading: false,
Orientation.landscape || // 假装使用一个非空变量避免Obx检测不到而罢工
plPlayerController?.isFullScreen.value == true pinned: videoDetailController.autoPlay.value ^
? MediaQuery.sizeOf(context).height - false ^
(MediaQuery.of(context).orientation == videoDetailController.autoPlay.value,
Orientation.landscape elevation: 0,
? 0 scrolledUnderElevation: 0,
: MediaQuery.of(context).padding.top) forceElevated: innerBoxIsScrolled,
: videoHeight, expandedHeight: MediaQuery.of(context).orientation ==
backgroundColor: Colors.black, Orientation.landscape ||
flexibleSpace: FlexibleSpaceBar( plPlayerController?.isFullScreen.value == true
background: PopScope( ? MediaQuery.sizeOf(context).height -
canPop: (MediaQuery.of(context).orientation ==
plPlayerController?.isFullScreen.value != true, Orientation.landscape
onPopInvoked: (bool didPop) { ? 0
if (plPlayerController?.isFullScreen.value == : MediaQuery.of(context).padding.top)
true) { : videoHeight,
plPlayerController! backgroundColor: Colors.black,
.triggerFullScreen(status: false); flexibleSpace: FlexibleSpaceBar(
} background: PopScope(
if (MediaQuery.of(context).orientation == canPop: plPlayerController?.isFullScreen.value !=
Orientation.landscape) { true,
verticalScreen(); onPopInvoked: (bool didPop) {
} if (plPlayerController?.isFullScreen.value ==
}, true) {
child: LayoutBuilder( plPlayerController!
builder: (BuildContext context, .triggerFullScreen(status: false);
BoxConstraints boxConstraints) { }
final double maxWidth = boxConstraints.maxWidth; if (MediaQuery.of(context).orientation ==
final double maxHeight = Orientation.landscape) {
boxConstraints.maxHeight; verticalScreen();
return Stack( }
children: <Widget>[ },
FutureBuilder( child: LayoutBuilder(
future: _futureBuilderFuture, builder: (BuildContext context,
builder: (BuildContext context, BoxConstraints boxConstraints) {
AsyncSnapshot snapshot) { final double maxWidth =
if (snapshot.hasData && boxConstraints.maxWidth;
snapshot.data['status']) { final double maxHeight =
return Obx( boxConstraints.maxHeight;
() => !videoDetailController return Stack(
.autoPlay.value children: <Widget>[
? const SizedBox() if (isShowing)
: PLVideoPlayer( FutureBuilder(
controller: future: _futureBuilderFuture,
plPlayerController!, builder: (BuildContext context,
headerControl: AsyncSnapshot snapshot) {
videoDetailController if (snapshot.hasData &&
.headerControl, snapshot.data['status']) {
danmuWidget: Obx( return Obx(
() => PlDanmaku( () =>
key: Key( !videoDetailController
videoDetailController .autoPlay.value
.danmakuCid ? nil
.value : PLVideoPlayer(
.toString()), controller:
cid: plPlayerController!,
videoDetailController headerControl:
.danmakuCid videoDetailController
.value, .headerControl,
playerController: danmuWidget: Obx(
plPlayerController!, () => PlDanmaku(
), key: Key(videoDetailController
), .danmakuCid
), .value
); .toString()),
} else { cid: videoDetailController
return const SizedBox(); .danmakuCid
} .value,
}, playerController:
), plPlayerController!,
),
),
),
);
} else {
return const SizedBox();
}
},
),
/// 关闭自动播放时 手动播放 /// 关闭自动播放时 手动播放
if (!videoDetailController if (!videoDetailController
.autoPlay.value) ...<Widget>[ .autoPlay.value) ...<Widget>[
Obx( Obx(
() => Visibility( () => Visibility(
visible: videoDetailController visible: videoDetailController
.isShowCover.value, .isShowCover.value,
child: Positioned( child: Positioned(
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
handlePlay(); handlePlay();
}, },
child: NetworkImgLayer( child: NetworkImgLayer(
type: 'emote', type: 'emote',
src: videoDetailController src: videoDetailController
.videoItem['pic'], .videoItem['pic'],
width: maxWidth, width: maxWidth,
height: maxHeight, height: maxHeight,
),
), ),
), ),
), ),
), ),
), Obx(
Obx( () => Visibility(
() => Visibility( visible: videoDetailController
visible: videoDetailController .isShowCover.value &&
.isShowCover.value && videoDetailController
videoDetailController .isEffective.value,
.isEffective.value, child: Stack(
child: Stack( children: [
children: [ Positioned(
Positioned( top: 0,
top: 0, left: 0,
left: 0, right: 0,
right: 0, child: AppBar(
child: AppBar( primary: false,
primary: false, foregroundColor:
foregroundColor: Colors.white,
Colors.white, elevation: 0,
elevation: 0, scrolledUnderElevation: 0,
scrolledUnderElevation: 0,
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: backgroundColor:
MaterialStateProperty Colors.transparent,
.resolveWith( actions: [
(states) { IconButton(
return Colors.white tooltip: '稍后再看',
.withOpacity(0.8); onPressed: () async {
}), var res = await UserHttp
.toViewLater(
bvid: videoDetailController
.bvid);
SmartDialog
.showToast(
res['msg']);
},
icon: const Icon(Icons
.history_outlined),
),
const SizedBox(
width: 14)
],
), ),
onPressed: () =>
handlePlay(),
icon: const Icon(
Icons.play_circle_outline,
size: 20,
),
label: const Text('轻触封面播放'),
), ),
), Positioned(
], right: 12,
)), bottom: 10,
), child: IconButton(
] tooltip: '播放',
], onPressed: () =>
); handlePlay(),
}, icon: Image.asset(
)), 'assets/images/play.png',
), width: 60,
), height: 60,
)),
),
],
)),
),
]
],
);
},
)),
),
);
},
), ),
]; ];
}, },
@ -500,7 +497,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
// }, // },
/// 不收回 /// 不收回
pinnedHeaderSliverHeightBuilder: () { pinnedHeaderSliverHeightBuilder: () {
return plPlayerController?.isFullScreen.value == true return MediaQuery.of(context).orientation ==
Orientation.landscape ||
plPlayerController?.isFullScreen.value == true
? MediaQuery.sizeOf(context).height ? MediaQuery.sizeOf(context).height
: pinnedHeaderHeight; : pinnedHeaderHeight;
}, },