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,18 +165,28 @@ 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 &&
snapshot.data['status']) {
return PLVideoPlayer(
controller: plPlayerController!, controller: plPlayerController!,
headerControl: HeaderControl( headerControl: HeaderControl(
controller: plPlayerController, controller: plPlayerController,
videoDetailCtr: videoDetailController, videoDetailCtr:
videoDetailController,
), ),
);
} else {
return const SizedBox();
}
}),
), ),
Visibility( Obx(
visible: isShowCover, () => Visibility(
visible: videoDetailController
.isShowCover.value,
child: Positioned( child: Positioned(
top: 0, top: 0,
left: 0, left: 0,
@ -190,20 +200,45 @@ class _VideoDetailPageState extends State<VideoDetailPage>
), ),
), ),
), ),
),
/// 关闭自动播放时 手动播放 /// 关闭自动播放时 手动播放
Visibility( Obx(
visible: isShowCover && () => Visibility(
visible: videoDetailController
.isShowCover.value &&
videoDetailController videoDetailController
.isEffective.value && .isEffective.value &&
!videoDetailController.autoPlay.value, !videoDetailController
child: Positioned( .autoPlay.value,
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: AppBar(
primary: false,
backgroundColor:
Colors.transparent,
actions: [
/// TODO
IconButton(
tooltip: '稍后再看',
onPressed: () {},
icon: const Icon(Icons
.history_outlined))
],
),
),
Positioned(
right: 12, right: 12,
bottom: 6, bottom: 6,
child: TextButton.icon( child: TextButton.icon(
style: ButtonStyle( style: ButtonStyle(
backgroundColor: backgroundColor:
MaterialStateProperty.resolveWith( MaterialStateProperty
.resolveWith(
(states) { (states) {
return Theme.of(context) return Theme.of(context)
.colorScheme .colorScheme
@ -211,7 +246,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
}), }),
), ),
onPressed: () => onPressed: () =>
videoDetailController.handlePlay(), videoDetailController
.handlePlay(),
icon: const Icon( icon: const Icon(
Icons.play_circle_outline, Icons.play_circle_outline,
size: 20, size: 20,
@ -219,6 +255,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
label: const Text('Play'), label: const Text('Play'),
), ),
), ),
],
)),
), ),
], ],
), ),