From 99657670b40b51bdca31ce7d0855ba77a1abcea9 Mon Sep 17 00:00:00 2001 From: sixbugs <972091604@qq.com> Date: Mon, 20 Nov 2023 03:21:56 -0600 Subject: [PATCH] Update bujuan_audio_handler.dart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改逻辑 --- lib/common/bujuan_audio_handler.dart | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/common/bujuan_audio_handler.dart b/lib/common/bujuan_audio_handler.dart index 1b38412..0c23c72 100644 --- a/lib/common/bujuan_audio_handler.dart +++ b/lib/common/bujuan_audio_handler.dart @@ -352,16 +352,21 @@ class BujuanAudioHandler extends BaseAudioHandler with SeekHandler, QueueHandler } void _setCurrIndex({bool next = false}) { - if (_audioServiceRepeatMode == AudioServiceRepeatMode.one) return; - var list = _audioServiceRepeatMode == AudioServiceRepeatMode.none ? _playListShut : _playList; - if (next ? _curIndex >= list.length - 1 : _curIndex <= 0) { - next ? _curIndex = 0 : _curIndex = list.length - 1; - } else { - next ? _curIndex++ : _curIndex--; - } - _box.put(playByIndex, _curIndex); + if (_audioServiceRepeatMode == AudioServiceRepeatMode.one) return; + + var list = _audioServiceRepeatMode == AudioServiceRepeatMode.none ? _playListShut : _playList; + + // 计算新的索引值 + _curIndex = next ? _curIndex + 1 : _curIndex - 1; + + // 如果超出索引范围,循环到列表的开始或结尾 + if (_curIndex >= list.length) { + _curIndex = 0; + } else if (_curIndex < 0) { + _curIndex = list.length - 1; + } - // StorageUtil().setInt(playByIndex, _curIndex); + _box.put(playByIndex, _curIndex); } @override