mod: video playing logic

This commit is contained in:
bggRGjQaUbCoE
2024-09-21 17:22:13 +08:00
parent 3263ff8949
commit 7707a78489
2 changed files with 24 additions and 2 deletions

View File

@@ -90,6 +90,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
@override
void initState() {
super.initState();
PlPlayerController.setPlayCallBack(playCallBack);
if (Get.arguments != null && Get.arguments['heroTag'] != null) {
heroTag = Get.arguments['heroTag'];
}
@@ -179,6 +180,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
}
}
void playCallBack() {
plPlayerController?.play();
}
// 流
appbarStreamListen() {
appbarStream = StreamController<double>();
@@ -236,9 +241,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
SmartDialog.showToast('not initialized');
return;
}
plPlayerController = videoDetailController.plPlayerController;
videoDetailController.isShowCover.value = false;
await videoDetailController.playerInit();
plPlayerController = videoDetailController.plPlayerController;
plPlayerController!.addStatusLister(playerListener);
listenFullScreenStatus();
await plPlayerController!.autoEnterFullscreen();
@@ -292,6 +297,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
void dispose() {
if (!Get.previousRoute.startsWith('/video')) {
ScreenBrightness().resetScreenBrightness();
PlPlayerController.setPlayCallBack(null);
}
appbarStream.close();
floating.dispose();
@@ -307,6 +313,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController!.removeStatusLister(playerListener);
fullScreenStatusListener.cancel();
plPlayerController!.dispose();
} else {
PlPlayerController.updatePlayCount();
}
videoPlayerServiceHandler.onVideoDetailDispose();
VideoDetailPage.routeObserver.unsubscribe(this);
@@ -343,6 +351,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
// 返回当前页面时
void didPopNext() async {
isShowing = true;
PlPlayerController.setPlayCallBack(playCallBack);
if (mounted) {
if (videoDetailController.brightness != null) {
plPlayerController

View File

@@ -290,9 +290,18 @@ class PlPlayerController {
return _instance != null;
}
static void setPlayCallBack(Function? playCallBack) {
_playCallBack = playCallBack;
}
static Function? _playCallBack;
static Future<void> playIfExists(
{bool repeat = false, bool hideControls = true}) async {
await _instance?.play(repeat: repeat, hideControls: hideControls);
// await _instance?.play(repeat: repeat, hideControls: hideControls);
if (_playCallBack != null) {
_playCallBack!();
}
}
// try to get PlayerStatus
@@ -1370,4 +1379,8 @@ class PlPlayerController {
));
_vttSubtitlesIndex.value = index;
}
static void updatePlayCount() {
_instance?._playerCount.value -= 1;
}
}