logo和名称替换
This commit is contained in:
@@ -3,13 +3,13 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgmj/hj_page/video/video_full_page.dart';
|
||||
import 'package:hgmj/hj_page/video/view/long_video_status.dart';
|
||||
import 'package:hgmj/hj_utils/codec_support.dart';
|
||||
import 'package:hgmj/hj_utils/play_diagnose.dart';
|
||||
import 'package:hgmj/hj_utils/const.dart';
|
||||
import 'package:hgmj/hj_utils/video_view_type.dart';
|
||||
import 'package:hgmj/tools_base/toast.dart';
|
||||
import 'package:wydj/hj_page/video/video_full_page.dart';
|
||||
import 'package:wydj/hj_page/video/view/long_video_status.dart';
|
||||
import 'package:wydj/hj_utils/codec_support.dart';
|
||||
import 'package:wydj/hj_utils/play_diagnose.dart';
|
||||
import 'package:wydj/hj_utils/const.dart';
|
||||
import 'package:wydj/hj_utils/video_view_type.dart';
|
||||
import 'package:wydj/tools_base/toast.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import '../../alert/video/buy_vip_alert.dart';
|
||||
@@ -73,7 +73,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
bool isFullScreen = false; // true:视频进入全屏页面
|
||||
RxBool isShowBuy = false.obs; // 显示购买和vip弹窗
|
||||
|
||||
late final TabController tabCtr = TabController(length: 2, vsync: this); // 简介/评论
|
||||
late final TabController tabCtr =
|
||||
TabController(length: 2, vsync: this); // 简介/评论
|
||||
CartoonMediaInfo? cartoonModel; //动漫
|
||||
ComicChapterInfo? currentEpisode; //动漫集数
|
||||
|
||||
@@ -101,7 +102,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
double get normalRatio => 16 / 9;
|
||||
|
||||
/// 实际播放比例:动漫和未初始化都用 16:9 兜底,否则用控制器报告的实际比例
|
||||
double get videoRatio => (!isCartoon && isInited) ? playerCtr!.value.aspectRatio : normalRatio;
|
||||
double get videoRatio =>
|
||||
(!isCartoon && isInited) ? playerCtr!.value.aspectRatio : normalRatio;
|
||||
|
||||
StreamSubscription? _pauseVideoSub;
|
||||
|
||||
@@ -138,13 +140,16 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
GuideManager().canShow(GuideFreeTrialSheet.scene) &&
|
||||
MineMsgProvider().payTier?.status == PayTier.newUnpay &&
|
||||
FreePlayManager().useFreePlay(videoModel) == true &&
|
||||
GuideFreeTrialSheet.isCountLow, //必须排在 useFreePlay 之后:它会先扣一次,扣完才是该显示的剩余数
|
||||
GuideFreeTrialSheet
|
||||
.isCountLow, //必须排在 useFreePlay 之后:它会先扣一次,扣完才是该显示的剩余数
|
||||
onShow: () async {
|
||||
// 先备好卡数据再暂停,否则拉数据期间视频白停几百毫秒;场景没配卡就压根不弹,别白暂停一下
|
||||
if (await loadGuideCard(GuideFreeTrialSheet.scene) == null || isDispose) return;
|
||||
if (await loadGuideCard(GuideFreeTrialSheet.scene) == null || isDispose)
|
||||
return;
|
||||
// 只暂停本来在播的:用户自己停在那看简介/评论时,弹完别擅自续播
|
||||
final wasPlaying = playerCtr?.value.isPlaying == true;
|
||||
if (wasPlaying) playerCtr?.pause(); // 图标由 VideoMenuView 的 Rx 自动跟,不用 update()
|
||||
if (wasPlaying)
|
||||
playerCtr?.pause(); // 图标由 VideoMenuView 的 Rx 自动跟,不用 update()
|
||||
final goVip = await GuideFreeTrialSheet.show();
|
||||
// 跳了会员页 / 已退页 / 期间被硬拦截弹了蒙层,都不能恢复播放
|
||||
if (!wasPlaying || goVip || isDispose || isShowBuy.value) return;
|
||||
@@ -159,8 +164,9 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
bool get _needPayGuide => videoStatus.isNeedPay;
|
||||
|
||||
/// 能连续看的秒数:有试看片就是试看片长,否则是正片免费时长
|
||||
int get _freeSeconds =>
|
||||
videoModel?.previewURL?.isNotEmpty == true ? (playerCtr?.value.duration.inSeconds ?? 0) : (videoModel?.freeTime ?? 0);
|
||||
int get _freeSeconds => videoModel?.previewURL?.isNotEmpty == true
|
||||
? (playerCtr?.value.duration.inSeconds ?? 0)
|
||||
: (videoModel?.freeTime ?? 0);
|
||||
|
||||
/// 各类「整片免看」权益:免费次数 / 免费区 / 动漫整本已购 / 动漫免费章节 / VIP 金币限免。
|
||||
/// 命中任一说明用户本来就能看完整片,场景1、场景2 都不该打扰他。
|
||||
@@ -169,8 +175,11 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
bool get _hasFreeWatchRight {
|
||||
if (FreePlayManager().useFreePlay(videoModel)) return true;
|
||||
if (videoModel?.freeArea == true) return true;
|
||||
if (cartoonModel?.mediaStatus?.hasPaid == true) return true; // 动漫整本解锁, 都可以看, 不管vip权限
|
||||
if (isCartoon && cartoonModel?.isFreeEpisodeNumber(currentEpisode?.episodeNumber) == true) return true;
|
||||
if (cartoonModel?.mediaStatus?.hasPaid == true)
|
||||
return true; // 动漫整本解锁, 都可以看, 不管vip权限
|
||||
if (isCartoon &&
|
||||
cartoonModel?.isFreeEpisodeNumber(currentEpisode?.episodeNumber) ==
|
||||
true) return true;
|
||||
return isVipCoinFree;
|
||||
}
|
||||
|
||||
@@ -199,7 +208,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
if (playerCtr?.value.isPlaying != true) return;
|
||||
_payGuideShown = true;
|
||||
// 先备好卡数据再暂停,否则拉数据期间视频白停几百毫秒;场景没配卡就压根不弹,别白暂停一下
|
||||
if (await loadGuideCard(GuideScene.videoPreviewEnd) == null || isDispose) return;
|
||||
if (await loadGuideCard(GuideScene.videoPreviewEnd) == null ||
|
||||
isDispose) return;
|
||||
playerCtr?.pause(); // 图标由 VideoMenuView 的 Rx 自动跟,不用 update()
|
||||
final goVip = await _showPayGuide();
|
||||
// 跳了会员页 / 已退页 / 期间被硬拦截弹了蒙层,都不能恢复播放
|
||||
@@ -218,7 +228,10 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
|
||||
/// 是否允许直接退页。false=先弹返回挽留(VIDEO_BACK):长视频 + 场景开关允许 + 本页未弹过。
|
||||
/// 供 PopScope.canPop 与返回箭头共用,类型跟当前在播内容走
|
||||
bool get canPop => _backGuideShown || isCartoon || !GuideManager().canShow(GuideScene.videoBack);
|
||||
bool get canPop =>
|
||||
_backGuideShown ||
|
||||
isCartoon ||
|
||||
!GuideManager().canShow(GuideScene.videoBack);
|
||||
|
||||
/// VIDEO_BACK:长视频返回挽留。弹优惠倒计时,标记已弹并 update() 让 canPop 放行后续返回。
|
||||
/// 用户是按了返回才弹的,所以挽留失败(点X/点蒙层/被互斥挡下)就把这次返回执行完;
|
||||
@@ -232,7 +245,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
try {
|
||||
await TimedPopupManager().trigger(
|
||||
canShow: () => GuideManager().canShow(GuideScene.videoBack),
|
||||
onShow: () async => goVip = await GuideCountdownDialog.show(scene: GuideScene.videoBack),
|
||||
onShow: () async => goVip =
|
||||
await GuideCountdownDialog.show(scene: GuideScene.videoBack),
|
||||
);
|
||||
} catch (e) {
|
||||
debugLog('showBackGuide', e.toString());
|
||||
@@ -276,7 +290,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
cartoonModel?.haxNextEpisode = episodeModel?.hasNext ?? true;
|
||||
videoModel?.mediaInfo = cartoonModel;
|
||||
currentEpisode = episodeModel?.list?.first;
|
||||
MediaContent? mediaContent = await ACGService.getMediaDetail(id: currentEpisode?.id ?? "");
|
||||
MediaContent? mediaContent =
|
||||
await ACGService.getMediaDetail(id: currentEpisode?.id ?? "");
|
||||
episodeModel?.list?.first.mediaContent = mediaContent;
|
||||
videoModel = cartoonModel?.toVideoModel(currentEpisode) ?? VideoModel();
|
||||
} else {
|
||||
@@ -350,7 +365,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
return;
|
||||
}
|
||||
isFullScreen = true;
|
||||
await Get.to(() => VideoFullPage(playCtr: playerCtr!, videoModel: videoModel));
|
||||
await Get.to(
|
||||
() => VideoFullPage(playCtr: playerCtr!, videoModel: videoModel));
|
||||
isFullScreen = false;
|
||||
}
|
||||
|
||||
@@ -358,7 +374,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
void exitFullScreen() {
|
||||
if (!isFullScreen) return;
|
||||
isFullScreen = false;
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
||||
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
Get.back();
|
||||
}
|
||||
@@ -395,7 +412,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
playerCtr = PlayerFactory.network(videoUrl); // 仅网络播放,不走本地文件
|
||||
try {
|
||||
await playerCtr?.initialize();
|
||||
if (isRetry) confirmPlatformView(); // 仅重试成功(同视频 textureView 挂、platformView 放出)才落本地
|
||||
if (isRetry)
|
||||
confirmPlatformView(); // 仅重试成功(同视频 textureView 挂、platformView 放出)才落本地
|
||||
update();
|
||||
} catch (e) {
|
||||
debugLog("视频初始化失败:$e play url = $videoUrl");
|
||||
@@ -443,7 +461,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
playerCtr?.addListener(_onProgress);
|
||||
int previewStart = videoModel?.previewStart ?? 0;
|
||||
if (previewStart > 0) {
|
||||
final canFree = FreePlayManager().useFreePlay(videoModel) || videoModel?.freeArea == true;
|
||||
final canFree = FreePlayManager().useFreePlay(videoModel) ||
|
||||
videoModel?.freeArea == true;
|
||||
// 免金币视频 / 有免费观看次数(vip视频):从头播,不需要 seekTo
|
||||
// 需要付费/会员才能看的视频,跳到预览起始位置开始播放
|
||||
if (!canFree && videoStatus.isNeedPay) {
|
||||
@@ -469,7 +488,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
if (!_isPreview()) {
|
||||
//每帧都走这里,videoStatus 是重算 getter,只读一次
|
||||
final status = videoStatus;
|
||||
final inFreeTime = videoModel?.isInFreeTime(playerCtr!.value.position.inSeconds) == true;
|
||||
final inFreeTime =
|
||||
videoModel?.isInFreeTime(playerCtr!.value.position.inSeconds) == true;
|
||||
final isPlaying = playerCtr?.value.isPlaying == true;
|
||||
if (inFreeTime || !isPlaying) return;
|
||||
// 全屏中:仍处于免费时长则不打扰;否则需付费的视频在播放时先退出全屏,给后续弹窗腾出空间
|
||||
@@ -484,7 +504,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
if (!isCartoon && status.isNeedVip) {
|
||||
// 刚退全屏要等 pop 动画和转屏落定再弹:exitFullScreen 的 Get.back() 带动画,
|
||||
// 此刻 push 会叠在正在 pop 的全屏页上,且弹窗高度取的是实时 Get.height,横屏下算出来是错的
|
||||
if (wasFullScreen) await Future.delayed(const Duration(milliseconds: 350));
|
||||
if (wasFullScreen)
|
||||
await Future.delayed(const Duration(milliseconds: 350));
|
||||
if (!isDispose) BuyVipAlert.show(videoId: videoModel?.id);
|
||||
}
|
||||
}
|
||||
@@ -527,7 +548,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
void _fallbackTo264() {
|
||||
if (isDispose || !isPlayingH265 || _forceH264) return;
|
||||
_forceH264 = true; // 本条视频后续重建都走 264
|
||||
debugLog("H.265 运行时报错,回退 264 续播 pos=${playerCtr?.value.position.inSeconds}");
|
||||
debugLog(
|
||||
"H.265 运行时报错,回退 264 续播 pos=${playerCtr?.value.position.inSeconds}");
|
||||
releasePlayer(); // 释放当前 → 下一帧按进度续播,选流因 _forceH264 走 264
|
||||
}
|
||||
|
||||
@@ -609,8 +631,10 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
isShowBuy.value = false;
|
||||
releasePlayer(rebuild: false);
|
||||
update();
|
||||
currentEpisode?.mediaContent ??= await ACGService.getMediaDetail(id: currentEpisode?.id ?? "");
|
||||
startPlay(model: cartoonModel?.toVideoModel(currentEpisode) ?? VideoModel());
|
||||
currentEpisode?.mediaContent ??=
|
||||
await ACGService.getMediaDetail(id: currentEpisode?.id ?? "");
|
||||
startPlay(
|
||||
model: cartoonModel?.toVideoModel(currentEpisode) ?? VideoModel());
|
||||
} catch (e) {
|
||||
debugLog(e);
|
||||
}
|
||||
@@ -618,7 +642,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
|
||||
/// 释放播放器。[rebuild]=false 只释放(切集前清理);[model] 非空则切新视频,为空则按上次进度续播。
|
||||
/// dispose 走下一帧,避免在播放回调中销毁导致 use-after-free
|
||||
void releasePlayer({VideoModel? model, bool rebuild = true, bool resetPos = false}) {
|
||||
void releasePlayer(
|
||||
{VideoModel? model, bool rebuild = true, bool resetPos = false}) {
|
||||
final old = playerCtr;
|
||||
old?.pause();
|
||||
// resetPos:预览片→正片场景,两者时间轴不对应,不能沿用预览片进度,从头播
|
||||
@@ -641,7 +666,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
/// 页面销毁清理:取消事件订阅 → 非预览视频上报观看记录 → 释放播放器
|
||||
@override
|
||||
void onClose() {
|
||||
isDispose = true; // 第一时间置位,让所有异步回调(initialize/postFrame/Future.delayed)能尽早 return
|
||||
isDispose =
|
||||
true; // 第一时间置位,让所有异步回调(initialize/postFrame/Future.delayed)能尽早 return
|
||||
TimedPopupManager().cancel(TimedPopupType.freeWatchPay);
|
||||
TimedPopupManager().cancel(TimedPopupType.videoPayAhead);
|
||||
|
||||
@@ -651,13 +677,15 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
if (playerCtr != null) {
|
||||
bool isPreview = false;
|
||||
if (videoModel?.previewURL?.isNotEmpty == true) {
|
||||
if (playerCtr?.dataSource.contains(videoModel?.previewURL ?? "") == true) {
|
||||
if (playerCtr?.dataSource.contains(videoModel?.previewURL ?? "") ==
|
||||
true) {
|
||||
isPreview = true;
|
||||
}
|
||||
}
|
||||
if (!isPreview) {
|
||||
try {
|
||||
_reportPlay(playerCtr?.value.position, playerCtr?.value.duration, videoModel);
|
||||
_reportPlay(
|
||||
playerCtr?.value.position, playerCtr?.value.duration, videoModel);
|
||||
} catch (e) {
|
||||
debugLog(e);
|
||||
}
|
||||
@@ -670,7 +698,8 @@ class VideoLogic extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
}
|
||||
|
||||
/// 上报播放记录(static:不碰实例状态,避免请求在飞时把已销毁的 logic 一起吊住)
|
||||
static Future<void> _reportPlay(Duration? position, Duration? duration, VideoModel? video) async {
|
||||
static Future<void> _reportPlay(
|
||||
Duration? position, Duration? duration, VideoModel? video) async {
|
||||
if (position == null || duration == null) return;
|
||||
if (position.inMilliseconds < 1000) return; // 不足 1 秒不记
|
||||
if (video?.videoType == 1) return; // 动漫不走这个接口
|
||||
|
||||
Reference in New Issue
Block a user