mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-10 19:20:12 +08:00
refactor: popular [wip]
mod: grpc request
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPalaX/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/http/member.dart';
|
||||
import 'package:PiliPalaX/utils/utils.dart';
|
||||
@@ -117,10 +118,7 @@ class VideoIntroController extends GetxController
|
||||
lastPlayCid.value = int.parse(Get.parameters['cid']!);
|
||||
isShowOnlineTotal =
|
||||
setting.get(SettingBoxKey.enableOnlineTotal, defaultValue: true);
|
||||
if (isShowOnlineTotal) {
|
||||
queryOnlineTotal();
|
||||
startTimer(); // 在页面加载时启动定时器
|
||||
}
|
||||
startTimer();
|
||||
queryVideoIntro();
|
||||
}
|
||||
|
||||
@@ -678,23 +676,35 @@ class VideoIntroController extends GetxController
|
||||
}
|
||||
|
||||
void startTimer() {
|
||||
const duration = Duration(seconds: 10); // 设置定时器间隔为10秒
|
||||
timer = Timer.periodic(duration, (Timer timer) {
|
||||
if (!isPaused) {
|
||||
queryOnlineTotal(); // 定时器回调函数,发起请求
|
||||
}
|
||||
});
|
||||
if (isShowOnlineTotal) {
|
||||
queryOnlineTotal();
|
||||
const duration = Duration(seconds: 10); // 设置定时器间隔为10秒
|
||||
timer ??= Timer.periodic(duration, (Timer timer) {
|
||||
if (!isPaused) {
|
||||
queryOnlineTotal(); // 定时器回调函数,发起请求
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void canelTimer() {
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
}
|
||||
|
||||
// 查看同时在看人数
|
||||
Future queryOnlineTotal() async {
|
||||
var result = await VideoHttp.onlineTotal(
|
||||
// var result = await VideoHttp.onlineTotal(
|
||||
// aid: IdUtils.bv2av(bvid),
|
||||
// bvid: bvid,
|
||||
// cid: lastPlayCid.value,
|
||||
// );
|
||||
dynamic result = await GrpcRepo.playerOnline(
|
||||
aid: IdUtils.bv2av(bvid),
|
||||
bvid: bvid,
|
||||
cid: lastPlayCid.value,
|
||||
);
|
||||
if (result['status']) {
|
||||
total.value = result['data']['total'];
|
||||
total.value = result['data'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:math';
|
||||
|
||||
import 'package:PiliPalaX/common/constants.dart';
|
||||
import 'package:PiliPalaX/common/widgets/list_sheet.dart';
|
||||
import 'package:PiliPalaX/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/models/bangumi/info.dart';
|
||||
import 'package:PiliPalaX/models/common/reply_type.dart';
|
||||
@@ -13,7 +14,6 @@ import 'package:PiliPalaX/pages/video/detail/introduction/widgets/intro_detail.d
|
||||
as video;
|
||||
import 'package:PiliPalaX/pages/video/detail/reply_reply/view.dart';
|
||||
import 'package:PiliPalaX/pages/video/detail/widgets/ai_detail.dart';
|
||||
import 'package:PiliPalaX/grpc/app/playeronline/v1/playeronline.dart';
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:PiliPalaX/utils/id_utils.dart';
|
||||
import 'package:auto_orientation/auto_orientation.dart';
|
||||
@@ -88,8 +88,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final onlineClient = OnlineClient();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -100,11 +98,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
}
|
||||
videoDetailController = Get.put(VideoDetailController(), tag: heroTag);
|
||||
|
||||
onlineClient.playerOnline(
|
||||
aid: IdUtils.bv2av(videoDetailController.bvid),
|
||||
cid: videoDetailController.cid.value,
|
||||
);
|
||||
|
||||
_videoReplyController = Get.put(
|
||||
VideoReplyController(videoDetailController.oid.value, '0', '1'),
|
||||
tag: heroTag);
|
||||
@@ -288,6 +281,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
PlPlayerController.setPlayCallBack(null);
|
||||
}
|
||||
videoDetailController.positionSubscription?.cancel();
|
||||
videoIntroController.canelTimer();
|
||||
appbarStream.close();
|
||||
floating.dispose();
|
||||
videoDetailController.floating?.dispose();
|
||||
@@ -320,6 +314,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
ScreenBrightness().resetScreenBrightness();
|
||||
|
||||
videoDetailController.positionSubscription?.cancel();
|
||||
videoIntroController.canelTimer();
|
||||
|
||||
videoDetailController.playerStatus =
|
||||
plPlayerController?.playerStatus.status.value;
|
||||
@@ -344,6 +339,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
void didPopNext() async {
|
||||
isShowing = true;
|
||||
PlPlayerController.setPlayCallBack(playCallBack);
|
||||
videoIntroController.startTimer();
|
||||
if (mounted) {
|
||||
if (videoDetailController.brightness != null) {
|
||||
plPlayerController
|
||||
|
||||
Reference in New Issue
Block a user