diff --git a/lib/common/widgets/video_card_h.dart b/lib/common/widgets/video_card_h.dart index 50bf9ae4..1467c5e6 100644 --- a/lib/common/widgets/video_card_h.dart +++ b/lib/common/widgets/video_card_h.dart @@ -1,7 +1,9 @@ +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:pilipala/common/constants.dart'; import 'package:pilipala/common/widgets/stat/view.dart'; +import 'package:pilipala/http/search.dart'; import 'package:pilipala/utils/utils.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; @@ -37,9 +39,14 @@ class VideoCardH extends StatelessWidget { }, child: InkWell( onTap: () async { - await Future.delayed(const Duration(milliseconds: 200)); - Get.toNamed('/video?bvid=$bvid&cid=${videoItem.cid}', - arguments: {'videoItem': videoItem, 'heroTag': heroTag}); + try { + int cid = + videoItem.cid ?? await SearchHttp.ab2c(aid: aid, bvid: bvid); + Get.toNamed('/video?bvid=$bvid&cid=$cid', + arguments: {'videoItem': videoItem, 'heroTag': heroTag}); + } catch (err) { + SmartDialog.showToast(err.toString()); + } }, child: Column( children: [ diff --git a/lib/http/api.dart b/lib/http/api.dart index 5d6e5813..c8a02d6e 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -154,4 +154,7 @@ class Api { // 记录视频播放进度 // https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/report.md static const String heartBeat = '/x/click-interface/web/heartbeat'; + + // 查询视频分P列表 (avid/bvid转cid) + static const String ab2c = '/x/player/pagelist'; } diff --git a/lib/http/search.dart b/lib/http/search.dart index 03345842..2afa59df 100644 --- a/lib/http/search.dart +++ b/lib/http/search.dart @@ -80,4 +80,15 @@ class SearchHttp { }; } } + + static Future ab2c({int? aid, String? bvid}) async { + Map data = {}; + if (aid != null) { + data['aid'] = aid; + } else if (bvid != null) { + data['bvid'] = bvid; + } + var res = await Request().get(Api.ab2c, data: {...data}); + return res.data['data'].first['cid']; + } } diff --git a/lib/models/search/result.dart b/lib/models/search/result.dart index 7e14d045..94eafec8 100644 --- a/lib/models/search/result.dart +++ b/lib/models/search/result.dart @@ -73,7 +73,6 @@ class SearchVideoItemModel { SearchVideoItemModel.fromJson(Map json) { type = json['type']; id = json['id']; - cid = json['id']; arcurl = json['arcurl']; aid = json['aid']; bvid = json['bvid']; @@ -83,14 +82,13 @@ class SearchVideoItemModel { videoReview = json['video_review']; pubdate = json['pubdate']; senddate = json['senddate']; - duration = test(json['duration']); - // duration = json['duration']; + duration = _dutation(json['duration']); owner = Owner.fromJson(json); stat = Stat.fromJson(json); } } -test(String duration) { +_dutation(String duration) { List timeList = duration.split(':'); int len = timeList.length; if (len == 2) { diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 85125cab..52069e3f 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -46,15 +46,15 @@ class _VideoDetailPageState extends State _meeduPlayerController = videoDetailController.meeduPlayerController; _playerEventSubs = _meeduPlayerController!.onPlayerStatusChanged.listen( (PlayerStatus status) { - // videoDetailController.markHeartBeat(); + videoDetailController.markHeartBeat(); if (status == PlayerStatus.playing) { Wakelock.enable(); isPlay = false; isShowCover = false; setState(() {}); - // videoDetailController.loopHeartBeat(); + videoDetailController.loopHeartBeat(); } else { - // videoDetailController.timer!.cancel(); + videoDetailController.timer!.cancel(); isPlay = true; setState(() {}); Wakelock.disable();