fix: reverse play

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-30 23:23:20 +08:00
parent cbe814fdd6
commit 20a89fbccb
6 changed files with 51 additions and 40 deletions

View File

@@ -64,6 +64,10 @@ class _ListSheetContentState extends State<ListSheetContent>
@override @override
void didUpdateWidget(ListSheetContent oldWidget) { void didUpdateWidget(ListSheetContent oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (widget.showTitle != false) {
return;
}
int currentIndex = _currentIndex; int currentIndex = _currentIndex;
void jumpToCurrent() { void jumpToCurrent() {
@@ -97,7 +101,7 @@ class _ListSheetContentState extends State<ListSheetContent>
void initState() { void initState() {
super.initState(); super.initState();
if (_isList) { if (_isList) {
_indexStream ??= StreamController<int>(); _indexStream ??= StreamController<int>.broadcast();
_ctr = TabController( _ctr = TabController(
vsync: this, vsync: this,
length: widget.season.sections.length, length: widget.season.sections.length,
@@ -358,29 +362,22 @@ class _ListSheetContentState extends State<ListSheetContent>
}, },
), ),
if (widget.season != null) if (widget.season != null)
_mediumButton( if (!_isList)
tooltip: '倒序播放', _reverseButton
icon: Icons.u_turn_right, else
onPressed: () async { StreamBuilder(
// jump to current stream: _indexStream?.stream,
if (_ctr != null && _ctr?.index != (_index)) { initialData: _index,
_ctr?.animateTo(_index); builder: (context, snapshot) {
await Future.delayed(const Duration(milliseconds: 225)); return snapshot.data == _index
} ? _reverseButton
try { : const SizedBox.shrink();
itemScrollController[_ctr?.index ?? 0].scrollTo( },
index: currentIndex, ),
duration: const Duration(milliseconds: 200),
);
} catch (_) {}
widget.onReverse?.call();
},
),
const Spacer(), const Spacer(),
StreamBuilder( StreamBuilder(
stream: _indexStream?.stream, stream: _indexStream?.stream,
initialData: 0, initialData: _index,
builder: (context, snapshot) => _mediumButton( builder: (context, snapshot) => _mediumButton(
tooltip: reverse[snapshot.data] ? '正序' : '反序', tooltip: reverse[snapshot.data] ? '正序' : '反序',
icon: !reverse[snapshot.data] icon: !reverse[snapshot.data]
@@ -436,6 +433,28 @@ class _ListSheetContentState extends State<ListSheetContent>
); );
} }
Widget get _reverseButton => _mediumButton(
tooltip: '倒序播放',
icon: Icons.u_turn_right,
onPressed: () async {
if (widget.showTitle == false) {
// 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();
},
);
Widget _mediumButton({ Widget _mediumButton({
String? tooltip, String? tooltip,
IconData? icon, IconData? icon,

View File

@@ -127,7 +127,6 @@ 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

@@ -102,7 +102,6 @@ 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

@@ -29,7 +29,7 @@ class SeasonPanel extends StatefulWidget {
} }
class _SeasonPanelState extends State<SeasonPanel> { class _SeasonPanelState extends State<SeasonPanel> {
int currentIndex = 0; RxInt currentIndex = 0.obs;
late VideoDetailController _videoDetailController; late VideoDetailController _videoDetailController;
StreamSubscription? _listener; StreamSubscription? _listener;
List<EpisodeItem> episodes = <EpisodeItem>[]; List<EpisodeItem> episodes = <EpisodeItem>[];
@@ -52,7 +52,7 @@ 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 = episodes.indexWhere( currentIndex.value = 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) { if (widget.pages != null && widget.pages!.length != 1) {
@@ -61,10 +61,9 @@ class _SeasonPanelState extends State<SeasonPanel> {
} }
_videoDetailController.seasonCid = p0; _videoDetailController.seasonCid = p0;
_findEpisode(); _findEpisode();
currentIndex = episodes.indexWhere( currentIndex.value = episodes.indexWhere(
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid); (EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
if (!mounted) return; if (!mounted) return;
setState(() {});
}); });
} }
@@ -112,11 +111,6 @@ class _SeasonPanelState extends State<SeasonPanel> {
_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),
@@ -137,11 +131,13 @@ class _SeasonPanelState extends State<SeasonPanel> {
semanticLabel: "正在播放:", semanticLabel: "正在播放:",
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
Text( Obx(
'${currentIndex + 1}/${episodes.length}', () => Text(
style: Theme.of(context).textTheme.labelMedium, '${currentIndex.value + 1}/${episodes.length}',
semanticsLabel: style: Theme.of(context).textTheme.labelMedium,
'${currentIndex + 1}集,共${episodes.length}', semanticsLabel:
'${currentIndex.value + 1}集,共${episodes.length}',
),
), ),
const SizedBox(width: 6), const SizedBox(width: 6),
const Icon( const Icon(

View File

@@ -1577,7 +1577,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
); );
} }
showEpisodes(index, season, episodes, bvid, aid, cid, onReverse) { showEpisodes(index, season, episodes, bvid, aid, cid) {
Widget listSheetContent() => ListSheetContent( Widget listSheetContent() => ListSheetContent(
index: index, index: index,
season: season, season: season,
@@ -1600,7 +1600,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
onReverse: () { onReverse: () {
Get.back(); Get.back();
onReversePlay(); onReversePlay();
onReverse();
}, },
); );
if (isFullScreen) { if (isFullScreen) {

View File

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