diff --git a/lib/pages/video/controller.dart b/lib/pages/video/controller.dart index ef804642c..ca07d344b 100644 --- a/lib/pages/video/controller.dart +++ b/lib/pages/video/controller.dart @@ -132,6 +132,10 @@ class VideoDetailController extends GetxController String? audioUrl; Duration? defaultST; Duration? playedTime; + String get playedTimePos { + final pos = playedTime?.inMilliseconds; + return pos == null || pos == 0 ? '' : '?t=${pos / 1000}'; + } // 亮度 double? brightness; diff --git a/lib/pages/video/introduction/pgc/controller.dart b/lib/pages/video/introduction/pgc/controller.dart index cc59db5f9..613b6e494 100644 --- a/lib/pages/video/introduction/pgc/controller.dart +++ b/lib/pages/video/introduction/pgc/controller.dart @@ -143,7 +143,8 @@ class PgcIntroController extends CommonIntroController { showDialog( context: context, builder: (_) { - String videoUrl = '${HttpString.baseUrl}/bangumi/play/ep$epId'; + String videoUrl = + '${HttpString.baseUrl}/bangumi/play/ep$epId${videoDetailCtr.playedTimePos}'; return AlertDialog( clipBehavior: Clip.hardEdge, contentPadding: const EdgeInsets.symmetric(vertical: 12), diff --git a/lib/pages/video/introduction/ugc/controller.dart b/lib/pages/video/introduction/ugc/controller.dart index 998f7bd9b..07ee2a90e 100644 --- a/lib/pages/video/introduction/ugc/controller.dart +++ b/lib/pages/video/introduction/ugc/controller.dart @@ -302,7 +302,8 @@ class UgcIntroController extends CommonIntroController with ReloadMixin { context: context, builder: (_) { final videoDetail = this.videoDetail.value; - String videoUrl = '${HttpString.baseUrl}/video/$bvid'; + String videoUrl = + '${HttpString.baseUrl}/video/$bvid${videoDetailCtr.playedTimePos}'; return AlertDialog( clipBehavior: Clip.hardEdge, contentPadding: const EdgeInsets.symmetric(vertical: 12), diff --git a/lib/utils/app_scheme.dart b/lib/utils/app_scheme.dart index 251cb00e2..4758a0ea9 100644 --- a/lib/utils/app_scheme.dart +++ b/lib/utils/app_scheme.dart @@ -41,6 +41,18 @@ abstract final class PiliScheme { listener = appLinks.uriLinkStream.listen(routePush); } + static int? _videoProgress(Map queryParameters) { + if ((queryParameters['start_progress'] ?? queryParameters['dm_progress']) + case final p?) { + return int.tryParse(p); + } else if (queryParameters['t'] case final t0?) { + if (double.tryParse(t0) case final t1?) { + return (t1 * 1000).toInt(); + } + } + return null; + } + static Future routePushFromUrl( String url, { bool selfHandle = false, @@ -99,7 +111,7 @@ abstract final class PiliScheme { PageUtils.viewPgc( seasonId: isEp ? null : id, epId: isEp ? id : null, - progress: uri.queryParameters['start_progress'], + progress: _videoProgress(uri.queryParameters), ); return true; } @@ -121,7 +133,6 @@ abstract final class PiliScheme { // bilibili://video/{aid}/?comment_root_id=***&comment_secondary_id=*** final queryParameters = uri.queryParameters; if (queryParameters['comment_root_id'] != null) { - // to check // to video reply String? oid = uriDigitRegExp.firstMatch(path)?.group(1); int? rpid = int.tryParse(queryParameters['comment_root_id']!); @@ -146,11 +157,10 @@ abstract final class PiliScheme { final cid = queryParameters['cid']; if (cid != null) { bvid ??= IdUtils.av2bv(int.parse(aid!)); - final progress = queryParameters['dm_progress']; PageUtils.toVideoPage( bvid: bvid, cid: int.parse(cid), - progress: progress == null ? null : int.parse(progress), + progress: _videoProgress(queryParameters), off: off, ); } else { @@ -158,7 +168,7 @@ abstract final class PiliScheme { aid != null ? int.parse(aid) : null, bvid, off: off, - progress: queryParameters['dm_progress'], + progress: _videoProgress(queryParameters), ); } return true; @@ -629,12 +639,9 @@ abstract final class PiliScheme { case 'bangumi': // www.bilibili.com/bangumi/play/ep{eid}?start_progress={offset}&thumb_up_dm_id={dmid} // if (kDebugMode) debugPrint('番剧'); - final queryParameters = uri.queryParameters; bool hasMatch = PageUtils.viewPgcFromUri( path, - progress: - queryParameters['start_progress'] ?? - queryParameters['dm_progress'], + progress: _videoProgress(uri.queryParameters), ); if (hasMatch) { return true; @@ -662,7 +669,7 @@ abstract final class PiliScheme { res.av, res.bv, off: off, - progress: queryParameters['dm_progress'], + progress: _videoProgress(queryParameters), part: part, ); return true; @@ -850,7 +857,7 @@ abstract final class PiliScheme { String? bvid, { bool showDialog = true, bool off = false, - String? progress, + int? progress, // milliseconds String? part, }) async { try { @@ -872,7 +879,7 @@ abstract final class PiliScheme { aid: aid, bvid: bvid, cid: cid, - progress: progress == null ? null : int.parse(progress), + progress: progress, off: off, ); } diff --git a/lib/utils/page_utils.dart b/lib/utils/page_utils.dart index 121d8cb73..ad46a2397 100644 --- a/lib/utils/page_utils.dart +++ b/lib/utils/page_utils.dart @@ -736,7 +736,7 @@ abstract final class PageUtils { int? pgcType, String? cover, String? title, - int? progress, + int? progress, // milliseconds Map? extraArguments, bool off = false, }) { @@ -773,7 +773,7 @@ abstract final class PageUtils { static bool viewPgcFromUri( String uri, { bool isPgc = true, - String? progress, + int? progress, // milliseconds int? aid, }) { RegExpMatch? match = _pgcRegex.firstMatch(uri); @@ -817,7 +817,7 @@ abstract final class PageUtils { static Future viewPgc({ dynamic seasonId, dynamic epId, - String? progress, + int? progress, // milliseconds }) async { try { SmartDialog.showLoading(msg: '资源获取中'); @@ -837,7 +837,7 @@ abstract final class PageUtils { seasonId: response.seasonId, epId: episode.epId, cover: episode.cover, - progress: progress == null ? null : int.tryParse(progress), + progress: progress, extraArguments: { 'pgcApi': true, 'pgcItem': response, @@ -886,7 +886,7 @@ abstract final class PageUtils { epId: episode.epId, pgcType: response.type, cover: episode.cover, - progress: progress == null ? null : int.tryParse(progress), + progress: progress, extraArguments: { 'pgcItem': response, },