fix: 历史记录
This commit is contained in:
@ -61,7 +61,6 @@ class VideoDetailController extends GetxController
|
||||
|
||||
ReplyItemModel? firstFloor;
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
Timer? timer;
|
||||
RxString bgCover = ''.obs;
|
||||
PlPlayerController plPlayerController = PlPlayerController.getInstance();
|
||||
|
||||
@ -69,6 +68,8 @@ class VideoDetailController extends GetxController
|
||||
late String videoUrl;
|
||||
late String audioUrl;
|
||||
late Duration defaultST;
|
||||
// 默认记录历史记录
|
||||
bool enableHeart = true;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -90,6 +91,11 @@ class VideoDetailController extends GetxController
|
||||
autoPlay.value =
|
||||
setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true);
|
||||
enableHA.value = setting.get(SettingBoxKey.enableHA, defaultValue: true);
|
||||
|
||||
if (user.get(UserBoxKey.userMid) == null ||
|
||||
localCache.get(LocalCacheKey.historyPause) == true) {
|
||||
enableHeart = false;
|
||||
}
|
||||
}
|
||||
|
||||
showReplyReplyPanel() {
|
||||
@ -164,6 +170,9 @@ class VideoDetailController extends GetxController
|
||||
: 'vertical',
|
||||
// 默认1倍速
|
||||
speed: 1.0,
|
||||
bvid: bvid,
|
||||
cid: cid,
|
||||
enableHeart: enableHeart,
|
||||
);
|
||||
}
|
||||
|
||||
@ -265,34 +274,4 @@ class VideoDetailController extends GetxController
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void loopHeartBeat() {
|
||||
timer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
markHeartBeat();
|
||||
});
|
||||
}
|
||||
|
||||
void markHeartBeat() async {
|
||||
if (user.get(UserBoxKey.userMid) == null) {
|
||||
return;
|
||||
}
|
||||
if (localCache.get(LocalCacheKey.historyStatus) == true) {
|
||||
return;
|
||||
}
|
||||
Duration progress = plPlayerController.position.value;
|
||||
await VideoHttp.heartBeat(
|
||||
bvid: bvid,
|
||||
cid: cid,
|
||||
progress: progress.inSeconds,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
markHeartBeat();
|
||||
if (timer != null && timer!.isActive) {
|
||||
timer!.cancel();
|
||||
}
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
@ -70,15 +70,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
void playerListener() {
|
||||
plPlayerController!.onPlayerStatusChanged.listen(
|
||||
(PlayerStatus status) async {
|
||||
videoDetailController.markHeartBeat();
|
||||
playerStatus = status;
|
||||
if (status == PlayerStatus.playing) {
|
||||
videoDetailController.isShowCover.value = false;
|
||||
videoDetailController.loopHeartBeat();
|
||||
} else {
|
||||
if (videoDetailController.timer != null) {
|
||||
videoDetailController.timer!.cancel();
|
||||
}
|
||||
// 播放完成停止 or 切换下一个
|
||||
if (status == PlayerStatus.completed) {
|
||||
// 当只有1p或多p未打开自动播放时,播放完成还原进度条,展示控制栏
|
||||
@ -102,18 +97,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
void dispose() {
|
||||
plPlayerController!.pause();
|
||||
plPlayerController!.dispose();
|
||||
if (videoDetailController.timer != null) {
|
||||
videoDetailController.timer!.cancel();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
// 离开当前页面时
|
||||
void didPushNext() async {
|
||||
if (videoDetailController.timer!.isActive) {
|
||||
videoDetailController.timer!.cancel();
|
||||
}
|
||||
videoDetailController.defaultST = plPlayerController!.position.value;
|
||||
plPlayerController!.pause();
|
||||
super.didPushNext();
|
||||
@ -127,9 +116,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
plPlayerController!.play();
|
||||
}
|
||||
if (!videoDetailController.timer!.isActive) {
|
||||
videoDetailController.loopHeartBeat();
|
||||
}
|
||||
super.didPopNext();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user