mod: 视频详情页代码整理

This commit is contained in:
guozhigq
2023-08-03 22:55:16 +08:00
parent 99a3ff81e0
commit df41a53eff
2 changed files with 98 additions and 58 deletions

View File

@ -54,6 +54,8 @@ class VideoDetailController extends GetxController
RxBool autoPlay = true.obs; RxBool autoPlay = true.obs;
// 视频资源是否有效 // 视频资源是否有效
RxBool isEffective = true.obs; RxBool isEffective = true.obs;
// 封面图的展示
RxBool isShowCover = true.obs;
@override @override
void onInit() { void onInit() {
@ -74,7 +76,7 @@ class VideoDetailController extends GetxController
heroTag = Get.arguments['heroTag']; heroTag = Get.arguments['heroTag'];
} }
tabCtr = TabController(length: 2, vsync: this); tabCtr = TabController(length: 2, vsync: this);
queryVideoUrl(); // queryVideoUrl();
} }
showReplyReplyPanel() { showReplyReplyPanel() {
@ -119,9 +121,9 @@ class VideoDetailController extends GetxController
playerInit(firstVideo, audioUrl, defaultST: position); playerInit(firstVideo, audioUrl, defaultST: position);
} }
playerInit(firstVideo, audioSource, Future playerInit(firstVideo, audioSource,
{Duration defaultST = Duration.zero, int duration = 0}) async { {Duration defaultST = Duration.zero, int duration = 0}) async {
plPlayerController.setDataSource( await plPlayerController.setDataSource(
DataSource( DataSource(
videoSource: firstVideo.baseUrl, videoSource: firstVideo.baseUrl,
audioSource: audioSource, audioSource: audioSource,
@ -149,7 +151,7 @@ class VideoDetailController extends GetxController
} }
// 视频链接 // 视频链接
queryVideoUrl() async { Future queryVideoUrl() async {
var result = await VideoHttp.videoUrl(cid: cid, bvid: bvid); var result = await VideoHttp.videoUrl(cid: cid, bvid: bvid);
if (result['status']) { if (result['status']) {
data = result['data']; data = result['data'];
@ -168,7 +170,7 @@ class VideoDetailController extends GetxController
if (firstAudio.id != null) { if (firstAudio.id != null) {
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!; currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;
} }
playerInit( await playerInit(
firstVideo, firstVideo,
audioUrl, audioUrl,
defaultST: Duration(milliseconds: data.lastPlayTime!), defaultST: Duration(milliseconds: data.lastPlayTime!),

View File

@ -35,12 +35,13 @@ class _VideoDetailPageState extends State<VideoDetailPage>
late StreamController<double> appbarStream; late StreamController<double> appbarStream;
PlayerStatus playerStatus = PlayerStatus.playing; PlayerStatus playerStatus = PlayerStatus.playing;
bool isShowCover = true; // bool isShowCover = true;
double doubleOffset = 0; double doubleOffset = 0;
Box localCache = GStrorage.localCache; Box localCache = GStrorage.localCache;
late double statusBarHeight; late double statusBarHeight;
final videoHeight = Get.size.width * 9 / 16; final videoHeight = Get.size.width * 9 / 16;
late Future _futureBuilderFuture;
@override @override
void initState() { void initState() {
@ -51,12 +52,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
videoDetailController.markHeartBeat(); videoDetailController.markHeartBeat();
playerStatus = status; playerStatus = status;
if (status == PlayerStatus.playing) { if (status == PlayerStatus.playing) {
isShowCover = false; videoDetailController.isShowCover.value = false;
setState(() {});
videoDetailController.loopHeartBeat(); videoDetailController.loopHeartBeat();
} else { } else {
videoDetailController.timer!.cancel(); videoDetailController.timer!.cancel();
// setState(() {});
// 播放完成停止 or 切换下一个 // 播放完成停止 or 切换下一个
if (status == PlayerStatus.completed) { if (status == PlayerStatus.completed) {
// 当只有1p或多p未打开自动播放时播放完成还原进度条展示控制栏 // 当只有1p或多p未打开自动播放时播放完成还原进度条展示控制栏
@ -78,6 +77,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
); );
statusBarHeight = localCache.get('statusBarHeight'); statusBarHeight = localCache.get('statusBarHeight');
_futureBuilderFuture = videoDetailController.queryVideoUrl();
} }
void continuePlay() async { void continuePlay() async {
@ -165,60 +165,98 @@ class _VideoDetailPageState extends State<VideoDetailPage>
tag: videoDetailController.heroTag, tag: videoDetailController.heroTag,
child: Stack( child: Stack(
children: [ children: [
if (plPlayerController! FutureBuilder(
.videoPlayerController != future: _futureBuilderFuture,
null) builder: ((context, snapshot) {
PLVideoPlayer( if (snapshot.hasData &&
controller: plPlayerController!, snapshot.data['status']) {
headerControl: HeaderControl( return PLVideoPlayer(
controller: plPlayerController, controller: plPlayerController!,
videoDetailCtr: videoDetailController, headerControl: HeaderControl(
), controller: plPlayerController,
), videoDetailCtr:
Visibility( videoDetailController,
visible: isShowCover, ),
child: Positioned( );
top: 0, } else {
left: 0, return const SizedBox();
right: 0, }
child: NetworkImgLayer( }),
type: 'emote', ),
src: videoDetailController Obx(
.videoItem['pic'], () => Visibility(
width: maxWidth, visible: videoDetailController
height: maxHeight, .isShowCover.value,
child: Positioned(
top: 0,
left: 0,
right: 0,
child: NetworkImgLayer(
type: 'emote',
src: videoDetailController
.videoItem['pic'],
width: maxWidth,
height: maxHeight,
),
), ),
), ),
), ),
/// 关闭自动播放时 手动播放 /// 关闭自动播放时 手动播放
Visibility( Obx(
visible: isShowCover && () => Visibility(
videoDetailController visible: videoDetailController
.isEffective.value && .isShowCover.value &&
!videoDetailController.autoPlay.value, videoDetailController
child: Positioned( .isEffective.value &&
right: 12, !videoDetailController
bottom: 6, .autoPlay.value,
child: TextButton.icon( child: Stack(
style: ButtonStyle( children: [
backgroundColor: Positioned(
MaterialStateProperty.resolveWith( top: 0,
(states) { left: 0,
return Theme.of(context) right: 0,
.colorScheme child: AppBar(
.primaryContainer; primary: false,
}), backgroundColor:
), Colors.transparent,
onPressed: () => actions: [
videoDetailController.handlePlay(), /// TODO
icon: const Icon( IconButton(
Icons.play_circle_outline, tooltip: '稍后再看',
size: 20, onPressed: () {},
), icon: const Icon(Icons
label: const Text('Play'), .history_outlined))
), ],
), ),
),
Positioned(
right: 12,
bottom: 6,
child: TextButton.icon(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty
.resolveWith(
(states) {
return Theme.of(context)
.colorScheme
.primaryContainer;
}),
),
onPressed: () =>
videoDetailController
.handlePlay(),
icon: const Icon(
Icons.play_circle_outline,
size: 20,
),
label: const Text('Play'),
),
),
],
)),
), ),
], ],
), ),