feat: season: reverse play #70

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-30 21:03:03 +08:00
parent ae6c6431f3
commit 04583e92b7
8 changed files with 127 additions and 34 deletions

View File

@@ -17,14 +17,16 @@ import '../../utils/utils.dart';
class ListSheetContent extends StatefulWidget { class ListSheetContent extends StatefulWidget {
const ListSheetContent({ const ListSheetContent({
super.key, super.key,
this.index, this.index, // tab index
this.season, this.season,
required this.episodes, this.episodes,
this.bvid, this.bvid,
this.aid, this.aid,
required this.currentCid, required this.currentCid,
required this.changeFucCall, required this.changeFucCall,
this.onClose, this.onClose,
this.onReverse,
this.showTitle,
}); });
final dynamic index; final dynamic index;
@@ -35,6 +37,8 @@ class ListSheetContent extends StatefulWidget {
final int currentCid; final int currentCid;
final Function changeFucCall; final Function changeFucCall;
final VoidCallback? onClose; final VoidCallback? onClose;
final VoidCallback? onReverse;
final bool? showTitle;
@override @override
State<ListSheetContent> createState() => _ListSheetContentState(); State<ListSheetContent> createState() => _ListSheetContentState();
@@ -47,10 +51,11 @@ class _ListSheetContentState extends State<ListSheetContent>
late List<bool> reverse; late List<bool> reverse;
int get _index => widget.index ?? 0; int get _index => widget.index ?? 0;
bool get _isList => late final bool _isList = widget.season != null &&
widget.season != null &&
widget.season?.sections is List && widget.season?.sections is List &&
widget.season.sections.length > 1; widget.season.sections.length > 1;
dynamic get episodes =>
widget.episodes ?? widget.season?.sections[_index].episodes;
TabController? _ctr; TabController? _ctr;
StreamController? _indexStream; StreamController? _indexStream;
int? _seasonFav; int? _seasonFav;
@@ -59,11 +64,34 @@ class _ListSheetContentState extends State<ListSheetContent>
@override @override
void didUpdateWidget(ListSheetContent oldWidget) { void didUpdateWidget(ListSheetContent oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
currentIndex = _currentIndex; int currentIndex = _currentIndex;
void jumpToCurrent() {
if (this.currentIndex != currentIndex) {
this.currentIndex = currentIndex;
try {
itemScrollController[_index].jumpTo(index: currentIndex);
} catch (_) {}
}
} }
int get _currentIndex => // jump to current
max(0, widget.episodes.indexWhere((e) => e.cid == widget.currentCid)); if (_ctr != null && widget.index != _ctr?.index) {
_ctr?.animateTo(_index);
Future.delayed(const Duration(milliseconds: 225)).then((_) {
jumpToCurrent();
});
} else {
jumpToCurrent();
}
}
int get _currentIndex => max(
0,
_isList
? widget.season.sections[_ctr?.index].episodes
.indexWhere((e) => e.cid == widget.currentCid)
: episodes.indexWhere((e) => e.cid == widget.currentCid));
@override @override
void initState() { void initState() {
@@ -150,6 +178,7 @@ class _ListSheetContentState extends State<ListSheetContent>
} }
SmartDialog.showToast('切换到:$title'); SmartDialog.showToast('切换到:$title');
widget.onClose?.call(); widget.onClose?.call();
currentIndex = index;
widget.changeFucCall( widget.changeFucCall(
episode is bangumi.EpisodeItem ? episode.epId : null, episode is bangumi.EpisodeItem ? episode.epId : null,
episode.runtimeType.toString() == "EpisodeItem" episode.runtimeType.toString() == "EpisodeItem"
@@ -242,11 +271,13 @@ class _ListSheetContentState extends State<ListSheetContent>
children: [ children: [
Container( Container(
height: 45, height: 45,
padding: const EdgeInsets.only(left: 14, right: 14), padding: EdgeInsets.symmetric(
horizontal: widget.showTitle != false ? 14 : 6),
child: Row( child: Row(
children: [ children: [
if (widget.showTitle != false)
Text( Text(
'合集${_isList ? widget.season.epCount : widget.episodes?.length ?? ''}', '合集(${_isList ? widget.season.epCount : episodes?.length ?? ''})',
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
StreamBuilder( StreamBuilder(
@@ -286,7 +317,7 @@ class _ListSheetContentState extends State<ListSheetContent>
? widget.season.sections[_ctr?.index].episodes ? widget.season.sections[_ctr?.index].episodes
.length - .length -
1 1
: widget.episodes.length - 1, : episodes.length - 1,
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
); );
} catch (_) {} } catch (_) {}
@@ -303,7 +334,7 @@ class _ListSheetContentState extends State<ListSheetContent>
? widget.season.sections[_ctr?.index].episodes ? widget.season.sections[_ctr?.index].episodes
.length - .length -
1 1
: widget.episodes.length - 1 : episodes.length - 1
: 0, : 0,
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
); );
@@ -326,6 +357,33 @@ class _ListSheetContentState extends State<ListSheetContent>
} catch (_) {} } catch (_) {}
}, },
), ),
if (widget.season != null)
_mediumButton(
tooltip: '倒叙播放',
icon: Icons.u_turn_right,
onPressed: () async {
// jump to current
if (_ctr != null && _ctr?.index != (_index)) {
_ctr?.animateTo(_index);
await Future.delayed(const Duration(milliseconds: 225));
}
try {
itemScrollController[_ctr?.index ?? 0].scrollTo(
index: currentIndex,
duration: const Duration(milliseconds: 200),
);
} catch (_) {}
widget.onReverse?.call();
WidgetsBinding.instance.addPostFrameCallback((_) {
try {
itemScrollController[_ctr?.index ?? 0].jumpTo(
index: currentIndex,
);
} catch (_) {}
});
},
),
const Spacer(), const Spacer(),
StreamBuilder( StreamBuilder(
stream: _indexStream?.stream, stream: _indexStream?.stream,
@@ -378,7 +436,7 @@ class _ListSheetContentState extends State<ListSheetContent>
index, widget.season.sections[index].episodes), index, widget.season.sections[index].episodes),
), ),
) )
: _buildBody(null, widget.episodes), : _buildBody(null, episodes),
), ),
], ],
), ),

View File

@@ -127,6 +127,7 @@ class _BangumiPanelState extends State<BangumiPanel> {
widget.pages[currentIndex].bvid, widget.pages[currentIndex].bvid,
widget.pages[currentIndex].aid, widget.pages[currentIndex].aid,
cid, cid,
null,
), ),
child: Text( child: Text(
widget.newEp?['desc']?.contains('连载') == true widget.newEp?['desc']?.contains('连载') == true

View File

@@ -11,7 +11,6 @@ import 'package:PiliPalaX/http/init.dart';
import 'package:PiliPalaX/http/user.dart'; import 'package:PiliPalaX/http/user.dart';
import 'package:PiliPalaX/models/video/later.dart'; import 'package:PiliPalaX/models/video/later.dart';
import 'package:PiliPalaX/models/video/play/subtitle.dart'; import 'package:PiliPalaX/models/video/play/subtitle.dart';
import 'package:PiliPalaX/models/video_detail_res.dart';
import 'package:PiliPalaX/pages/video/detail/introduction/controller.dart'; import 'package:PiliPalaX/pages/video/detail/introduction/controller.dart';
import 'package:PiliPalaX/pages/video/detail/related/controller.dart'; import 'package:PiliPalaX/pages/video/detail/related/controller.dart';
import 'package:PiliPalaX/pages/video/detail/reply/controller.dart'; import 'package:PiliPalaX/pages/video/detail/reply/controller.dart';
@@ -225,7 +224,6 @@ class VideoDetailController extends GetxController
late final horizontalSeasonPanel = GStorage.horizontalSeasonPanel; late final horizontalSeasonPanel = GStorage.horizontalSeasonPanel;
late int seasonCid = 0; late int seasonCid = 0;
late RxInt seasonIndex = 0.obs; late RxInt seasonIndex = 0.obs;
late RxList<EpisodeItem> episodes = <EpisodeItem>[].obs;
late final bool enableSponsorBlock; late final bool enableSponsorBlock;
PlayerStatus? playerStatus; PlayerStatus? playerStatus;

View File

@@ -127,10 +127,13 @@ class VideoIntroController extends GetxController
// 获取视频简介&分p // 获取视频简介&分p
Future queryVideoIntro() async { Future queryVideoIntro() async {
await queryVideoTags(); queryVideoTags();
var result = await VideoHttp.videoIntro(bvid: bvid); var result = await VideoHttp.videoIntro(bvid: bvid);
if (result['status']) { if (result['status']) {
videoDetail.value = result['data']!; if (videoDetail.value.ugcSeason?.id == result['data']?.ugcSeason?.id) {
result['data']?.ugcSeason = videoDetail.value.ugcSeason;
}
videoDetail.value = result['data'];
videoItem!['staff'] = result['data'].staff; videoItem!['staff'] = result['data'].staff;
try { try {
final videoDetailController = final videoDetailController =

View File

@@ -102,6 +102,7 @@ class _PagesPanelState extends State<PagesPanel> {
widget.bvid, widget.bvid,
IdUtils.bv2av(widget.bvid), IdUtils.bv2av(widget.bvid),
cid, cid,
null,
), ),
child: Text( child: Text(
'${widget.pages.length}', '${widget.pages.length}',

View File

@@ -32,6 +32,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
int currentIndex = 0; int currentIndex = 0;
late VideoDetailController _videoDetailController; late VideoDetailController _videoDetailController;
StreamSubscription? _listener; StreamSubscription? _listener;
List<EpisodeItem> episodes = <EpisodeItem>[];
@override @override
void initState() { void initState() {
@@ -43,7 +44,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
/// 根据 cid 找到对应集,找到对应 episodes /// 根据 cid 找到对应集,找到对应 episodes
/// 有多个episodes时只显示其中一个 /// 有多个episodes时只显示其中一个
_findEpisode(); _findEpisode();
if (_videoDetailController.episodes.isEmpty) { if (episodes.isEmpty) {
return; return;
} }
@@ -51,14 +52,16 @@ class _SeasonPanelState extends State<SeasonPanel> {
// episodes = widget.ugcSeason.sections! // episodes = widget.ugcSeason.sections!
// .firstWhere((e) => e.seasonId == widget.ugcSeason.id) // .firstWhere((e) => e.seasonId == widget.ugcSeason.id)
// .episodes; // .episodes;
currentIndex = _videoDetailController.episodes.indexWhere( currentIndex = episodes.indexWhere(
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid); (EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
_listener = _videoDetailController.cid.listen((int p0) { _listener = _videoDetailController.cid.listen((int p0) {
if (widget.pages != null && widget.pages!.length != 1) {
bool isPart = widget.pages?.indexWhere((item) => item.cid == p0) != -1; bool isPart = widget.pages?.indexWhere((item) => item.cid == p0) != -1;
if (isPart) return; if (isPart) return;
}
_videoDetailController.seasonCid = p0; _videoDetailController.seasonCid = p0;
_findEpisode(); _findEpisode();
currentIndex = _videoDetailController.episodes.indexWhere( currentIndex = episodes.indexWhere(
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid); (EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
if (!mounted) return; if (!mounted) return;
setState(() {}); setState(() {});
@@ -84,7 +87,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_videoDetailController.episodes.isEmpty) { if (episodes.isEmpty) {
return const SizedBox(); return const SizedBox();
} }
return Builder(builder: (BuildContext context) { return Builder(builder: (BuildContext context) {
@@ -105,10 +108,15 @@ class _SeasonPanelState extends State<SeasonPanel> {
: () => widget.showEpisodes( : () => widget.showEpisodes(
_videoDetailController.seasonIndex.value, _videoDetailController.seasonIndex.value,
widget.ugcSeason, widget.ugcSeason,
_videoDetailController.episodes, null,
_videoDetailController.bvid, _videoDetailController.bvid,
null, null,
_videoDetailController.seasonCid, _videoDetailController.seasonCid,
() {
setState(() {
currentIndex = episodes.length - 1 - currentIndex;
});
},
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(8, 12, 8, 12), padding: const EdgeInsets.fromLTRB(8, 12, 8, 12),
@@ -130,10 +138,10 @@ class _SeasonPanelState extends State<SeasonPanel> {
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
Text( Text(
'${currentIndex + 1}/${_videoDetailController.episodes.length}', '${currentIndex + 1}/${episodes.length}',
style: Theme.of(context).textTheme.labelMedium, style: Theme.of(context).textTheme.labelMedium,
semanticsLabel: semanticsLabel:
'${currentIndex + 1}集,共${_videoDetailController.episodes.length}', '${currentIndex + 1}集,共${episodes.length}',
), ),
const SizedBox(width: 6), const SizedBox(width: 6),
const Icon( const Icon(
@@ -156,8 +164,10 @@ class _SeasonPanelState extends State<SeasonPanel> {
final List<EpisodeItem> episodesList = sections[i].episodes!; final List<EpisodeItem> episodesList = sections[i].episodes!;
for (int j = 0; j < episodesList.length; j++) { for (int j = 0; j < episodesList.length; j++) {
if (episodesList[j].cid == _videoDetailController.seasonCid) { if (episodesList[j].cid == _videoDetailController.seasonCid) {
if (_videoDetailController.seasonIndex.value != i) {
_videoDetailController.seasonIndex.value = i; _videoDetailController.seasonIndex.value = i;
_videoDetailController.episodes.value = episodesList; }
episodes = episodesList;
break; break;
} }
} }

View File

@@ -1505,8 +1505,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
child: Obx( child: Obx(
() => ListSheetContent( () => ListSheetContent(
index: videoDetailController.seasonIndex.value, index: videoDetailController.seasonIndex.value,
season: videoIntroController.videoDetail.value.ugcSeason!, season: videoIntroController.videoDetail.value.ugcSeason,
episodes: videoDetailController.episodes,
bvid: videoDetailController.bvid, bvid: videoDetailController.bvid,
aid: IdUtils.bv2av(videoDetailController.bvid), aid: IdUtils.bv2av(videoDetailController.bvid),
currentCid: videoDetailController.seasonCid, currentCid: videoDetailController.seasonCid,
@@ -1514,6 +1513,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
SearchType.media_bangumi SearchType.media_bangumi
? bangumiIntroController.changeSeasonOrbangu ? bangumiIntroController.changeSeasonOrbangu
: videoIntroController.changeSeasonOrbangu, : videoIntroController.changeSeasonOrbangu,
showTitle: false,
onReverse: onReversePlay,
), ),
), ),
), ),
@@ -1576,14 +1577,14 @@ class _VideoDetailPageState extends State<VideoDetailPage>
); );
} }
showEpisodes(index, season, episodes, bvid, aid, cid) { showEpisodes(index, season, episodes, bvid, aid, cid, onReverse) {
Widget listSheetContent() => ListSheetContent( Widget listSheetContent() => ListSheetContent(
index: index, index: index,
season: season, season: season,
episodes: episodes,
bvid: bvid, bvid: bvid,
aid: aid, aid: aid,
currentCid: cid, currentCid: cid,
episodes: episodes,
changeFucCall: changeFucCall:
videoDetailController.videoType == SearchType.media_bangumi videoDetailController.videoType == SearchType.media_bangumi
? bangumiIntroController.changeSeasonOrbangu ? bangumiIntroController.changeSeasonOrbangu
@@ -1596,6 +1597,11 @@ class _VideoDetailPageState extends State<VideoDetailPage>
Get.back(); Get.back();
} }
}, },
onReverse: () {
Get.back();
onReversePlay();
onReverse();
},
); );
if (isFullScreen) { if (isFullScreen) {
videoDetailController.bsController = videoDetailController.bsController =
@@ -1609,6 +1615,21 @@ class _VideoDetailPageState extends State<VideoDetailPage>
} }
} }
void onReversePlay() {
videoIntroController.videoDetail.value.ugcSeason!
.sections![videoDetailController.seasonIndex.value].episodes =
videoIntroController
.videoDetail
.value
.ugcSeason!
.sections![videoDetailController.seasonIndex.value]
.episodes!
.reversed
.toList();
videoDetailController.seasonIndex.refresh();
videoDetailController.cid.refresh();
}
void showViewPoints() { void showViewPoints() {
Widget listSheetContent(context, [bool isFS = false]) { Widget listSheetContent(context, [bool isFS = false]) {
int currentIndex = -1; int currentIndex = -1;

View File

@@ -411,6 +411,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
bvid, bvid,
IdUtils.bv2av(bvid), IdUtils.bv2av(bvid),
currentCid, currentCid,
null,
); );
}, },
), ),