开始进入修复阶段
This commit is contained in:
@@ -13,6 +13,7 @@ import '../utils/artwork_helper.dart';
|
||||
import '../repositories/playlist_repository.dart';
|
||||
import '../models/playlist.dart';
|
||||
import 'webdav_service.dart';
|
||||
import 'audio_player_handler.dart';
|
||||
|
||||
enum PlayMode {
|
||||
sequential,
|
||||
@@ -62,6 +63,9 @@ class AudioService extends ChangeNotifier {
|
||||
// ---- 当前播放的歌单 ID ----
|
||||
String? _currentPlaylistId;
|
||||
|
||||
// ⭐ 插入位置:在现有成员变量之后,方法之前
|
||||
AudioPlayerHandler? _handler; // ⭐ 添加这一行
|
||||
|
||||
// ---- 高频进度 ----
|
||||
final ValueNotifier<Duration> positionNotifier = ValueNotifier(Duration.zero);
|
||||
final ValueNotifier<Duration> durationNotifier = ValueNotifier(Duration.zero);
|
||||
@@ -115,6 +119,11 @@ class AudioService extends ChangeNotifier {
|
||||
_onSongChanged = callback;
|
||||
}
|
||||
|
||||
void setHandler(AudioPlayerHandler handler) {
|
||||
// ⭐ 添加这个方法
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
void togglePlayMode() {
|
||||
switch (_playMode) {
|
||||
case PlayMode.sequential:
|
||||
@@ -264,6 +273,8 @@ class AudioService extends ChangeNotifier {
|
||||
final song = _queue[_currentIndex];
|
||||
_currentSong = song;
|
||||
|
||||
_handler?.syncState(song);
|
||||
|
||||
_startListening();
|
||||
notifyListeners();
|
||||
|
||||
@@ -547,6 +558,8 @@ class AudioService extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void stopPlay() {
|
||||
// 停止底层播放器
|
||||
PlaybackService().stop(); // 新增
|
||||
_currentSong = null;
|
||||
_isPlaying = false;
|
||||
positionNotifier.value = Duration.zero;
|
||||
@@ -554,7 +567,6 @@ class AudioService extends ChangeNotifier {
|
||||
bufferedNotifier.value = Duration.zero;
|
||||
_stopListening();
|
||||
notifyListeners();
|
||||
// 停止时也保存一次
|
||||
savePlaybackState();
|
||||
}
|
||||
|
||||
@@ -821,6 +833,8 @@ class AudioService extends ChangeNotifier {
|
||||
_currentSong = song;
|
||||
_onSongChanged?.call(song);
|
||||
|
||||
_handler?.syncState(song); // ⭐ 添加这一行
|
||||
|
||||
debugPrint(
|
||||
'♻️ [AudioService] playback state restored: ${song.title} - ${song.artist}');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user