From 99917bac87058ef85d51278dc23e5cbe419ea89e Mon Sep 17 00:00:00 2001 From: lxh2875931338 Date: Fri, 28 Aug 2026 22:59:04 +0800 Subject: [PATCH] =?UTF-8?q?Core=20Freeze=EF=BC=9A=E6=A0=B8=E5=BF=83?= =?UTF-8?q?=E9=93=BE=E8=B7=AF=E5=8A=9F=E8=83=BD=E5=B7=B2=E7=BB=8F=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E8=AE=BE=E8=AE=A1=EF=BC=8C=E5=90=8E=E7=BB=AD=E8=BF=9B?= =?UTF-8?q?=E5=85=A5beta=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E6=8E=A5=E4=B8=8B=E6=9D=A5=E4=BC=9A=E5=9C=A8?= =?UTF-8?q?UI=E9=83=A8=E5=88=86=E5=BE=AE=E8=B0=83=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E9=A6=96=E4=B8=AARelease=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=881.1.0-Release=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/services/audio_service.dart | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/services/audio_service.dart b/lib/services/audio_service.dart index 8a2bc3b..607601e 100644 --- a/lib/services/audio_service.dart +++ b/lib/services/audio_service.dart @@ -779,7 +779,6 @@ class AudioService extends ChangeNotifier { debugPrint('💾 [AudioService] playback state saved'); } - /// 恢复播放状态 /// 恢复播放状态 Future restorePlaybackState() async { final state = await _db.getPlaybackState(); @@ -803,7 +802,9 @@ class AudioService extends ChangeNotifier { _queue = queue; _currentIndex = state['current_index'] as int; - if (_currentIndex >= _queue.length) _currentIndex = 0; + if (_currentIndex < 0 || _currentIndex >= _queue.length) { + _currentIndex = 0; + } final modeStr = state['play_mode'] as String? ?? 'sequential'; _playMode = modeStr == 'sequential' @@ -813,6 +814,20 @@ class AudioService extends ChangeNotifier { : PlayMode.shuffle; _currentPlaylistId = state['current_playlist_id'] as String?; + // ⭐⭐⭐ 关键修复:重建 _shuffledIndices 和 _shuffledIndex ⭐⭐⭐ + if (_playMode == PlayMode.shuffle) { + _shuffledIndices = List.generate(_queue.length, (i) => i); + _shuffledIndices.shuffle(); + _shuffledIndex = _shuffledIndices.indexOf(_currentIndex); + if (_shuffledIndex == -1) { + _shuffledIndex = 0; + _currentIndex = _shuffledIndices[0]; + } + } else { + _shuffledIndices = List.generate(_queue.length, (i) => i); + _shuffledIndex = _currentIndex; + } + // 保存待恢复的进度 final savedPos = state['position_ms'] as int? ?? 0; _pendingSeekPosition = Duration(milliseconds: savedPos); @@ -821,10 +836,11 @@ class AudioService extends ChangeNotifier { _currentSong = song; _onSongChanged?.call(song); - debugPrint( - '♻️ [AudioService] playback state restored: ${song.title} - ${song.artist}'); + debugPrint('♻️ [AudioService] playback state restored: ' + 'queue=${_queue.length}, index=$_currentIndex, ' + 'song=${song.title}, mode=$_playMode'); - // ⭐ 关键:加载音频但不自动播放 + // ⭐ 加载音频但不自动播放 await _loadRestoredPlayback(); return true;