fix video progress

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-06-13 10:02:17 +08:00
parent f37e332de9
commit 653a789896
5 changed files with 40 additions and 56 deletions

View File

@@ -208,19 +208,15 @@ abstract final class VideoHttp {
case .pgc:
final result = res.data['result'];
data = PlayUrlModel.fromJson(result['video_info']);
if (result['play_view_business_info']?['user_status']?['watch_progress']?['current_watch_progress']
case final int progress when progress > 0) {
data.lastPlayTime = progress;
}
data = PlayUrlModel.fromJson(result['video_info'])
..lastPlayTime =
result['play_view_business_info']?['user_status']?['watch_progress']?['current_watch_progress'];
case .pugv:
final result = res.data['data'];
data = PlayUrlModel.fromJson(result);
if (result['play_view_business_info']?['user_status']?['watch_progress']?['current_watch_progress']
case final int progress when progress > 0) {
data.lastPlayTime = progress;
}
data = PlayUrlModel.fromJson(result)
..lastPlayTime =
result['play_view_business_info']?['user_status']?['watch_progress']?['current_watch_progress'];
}
return Success(data);
} else if (epid != null && videoType == .ugc) {

View File

@@ -22,7 +22,7 @@ class PlayUrlModel {
this.seekType,
this.dash,
this.supportFormats,
this.lastPlayTime,
this._lastPlayTime = 0,
this.lastPlayCid,
});
@@ -42,7 +42,17 @@ class PlayUrlModel {
List<Durl>? durl;
List<FormatItem>? supportFormats;
Volume? volume;
int? lastPlayTime;
late int _lastPlayTime;
int get lastPlayTime => _lastPlayTime;
set lastPlayTime(int? value) {
if (value != null && value > 0) {
_lastPlayTime = value;
} else {
_lastPlayTime = 0;
}
}
int? lastPlayCid;
String? curLanguage;
Language? language;
@@ -69,9 +79,7 @@ class PlayUrlModel {
?.map<FormatItem>((e) => FormatItem.fromJson(e))
.toList();
volume = json['volume'] == null ? null : Volume.fromJson(json['volume']);
if (json['last_play_time'] case final int progress when progress > 0) {
lastPlayTime = progress;
}
lastPlayTime = json['last_play_time'];
lastPlayCid = json['last_play_cid'];
curLanguage = json['cur_language'];
language = json['language'] == null

View File

@@ -667,15 +667,8 @@ class VideoDetailController extends GetxController
return null;
}
Future<void> playerInit({
String? video,
String? audio,
Duration? seekToTime,
Duration? duration,
bool? autoplay,
Volume? volume,
}) async {
Duration? seek = seekToTime ?? defaultST ?? playedTime;
Future<void> playerInit({bool? autoplay}) async {
Duration? seek = defaultST ?? playedTime;
if (seek == null || seek == Duration.zero) {
seek = getFirstSegment();
}
@@ -688,15 +681,13 @@ class VideoDetailController extends GetxController
hasDashAudio: entry.hasDashAudio,
)
: NetworkSource(
videoSource: video ?? videoUrl!,
audioSource: audio ?? audioUrl,
videoSource: videoUrl!,
audioSource: audioUrl,
),
seekTo: seek,
duration:
duration ??
(data.timeLength == null
? null
: Duration(milliseconds: data.timeLength!)),
duration: data.timeLength == null
? null
: Duration(milliseconds: data.timeLength!),
isVertical: isVertical,
aid: aid,
bvid: bvid,
@@ -712,7 +703,7 @@ class VideoDetailController extends GetxController
},
width: firstVideo.width,
height: firstVideo.height,
volume: volume ?? this.volume,
volume: volume,
);
if (isClosed) return;
@@ -741,16 +732,13 @@ class VideoDetailController extends GetxController
return;
}
currLang.value = language;
queryVideoUrl(defaultST: playedTime);
queryVideoUrl(fromReset: true);
}
Volume? volume;
// 视频链接
Future<void> queryVideoUrl({
Duration? defaultST,
bool fromReset = false,
}) async {
Future<void> queryVideoUrl({bool fromReset = false}) async {
if (isFileSource) {
return _initPlayerIfNeeded();
}
@@ -790,11 +778,13 @@ class VideoDetailController extends GetxController
volume = data.volume;
final progress = args.remove('progress');
if (progress != null) {
this.defaultST = Duration(milliseconds: progress);
} else if (defaultST == null && data.lastPlayTime != null) {
this.defaultST = Duration(milliseconds: data.lastPlayTime!);
if (!fromReset) {
final progress = args.remove('progress');
if (progress != null) {
defaultST = Duration(milliseconds: progress);
} else {
defaultST = Duration(milliseconds: data.lastPlayTime);
}
}
if (!isUgc && !fromReset && plPlayerController.enablePgcSkip) {

View File

@@ -72,11 +72,7 @@ class VideoDetailPageV extends StatefulWidget {
}
class _VideoDetailPageVState extends State<VideoDetailPageV>
with
TickerProviderStateMixin,
RouteAware,
RouteAwareMixin,
WidgetsBindingObserver {
with RouteAware, RouteAwareMixin, WidgetsBindingObserver {
final heroTag = Get.arguments['heroTag'];
late final VideoDetailController videoDetailController;
@@ -1071,7 +1067,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
if (videoDetailController.tabCtr.length != tabs.length) {
videoDetailController.tabCtr.dispose();
videoDetailController.tabCtr = TabController(
vsync: this,
vsync: videoDetailController,
length: tabs.length,
initialIndex: tabs.isEmpty
? 0

View File

@@ -445,10 +445,7 @@ class HeaderControlState extends State<HeaderControl>
dense: true,
onTap: () {
Get.back();
videoDetailCtr.queryVideoUrl(
defaultST: videoDetailCtr.playedTime,
fromReset: true,
);
videoDetailCtr.queryVideoUrl(fromReset: true);
},
leading: const Icon(Icons.refresh_outlined, size: 20),
title: const Text('重载视频', style: titleStyle),
@@ -493,10 +490,7 @@ class HeaderControlState extends State<HeaderControl>
VideoUtils.cdnService = result;
setting.put(SettingBoxKey.CDNService, result.name);
SmartDialog.showToast('已设置为 ${result.desc},正在重载视频');
videoDetailCtr.queryVideoUrl(
defaultST: videoDetailCtr.playedTime,
fromReset: true,
);
videoDetailCtr.queryVideoUrl(fromReset: true);
}
},
),