全部包名与名称确定,后台播放能力已完整,准备进入媒体信息推送部分
This commit is contained in:
@@ -48,6 +48,9 @@ class AudioService extends ChangeNotifier {
|
||||
bool _listening = false;
|
||||
final List<StreamSubscription> _subscriptions = [];
|
||||
|
||||
// ⭐ 防重入标志
|
||||
bool _handlingCompletion = false;
|
||||
|
||||
// ---- Getter(高频字段不走 ChangeNotifier) ----
|
||||
Song? get currentSong => _currentSong;
|
||||
bool get isPlaying => _isPlaying;
|
||||
@@ -240,12 +243,11 @@ class AudioService extends ChangeNotifier {
|
||||
player.stream.playing.listen((playing) {
|
||||
if (_isPlaying != playing) {
|
||||
_isPlaying = playing;
|
||||
notifyListeners(); // 只有播放状态变化才刷新
|
||||
notifyListeners();
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
// ⭐ 进度更新:只更新 ValueNotifier,不触发全局重建
|
||||
_subscriptions.add(
|
||||
player.stream.position.listen((position) {
|
||||
positionNotifier.value = position;
|
||||
@@ -264,6 +266,7 @@ class AudioService extends ChangeNotifier {
|
||||
}),
|
||||
);
|
||||
|
||||
// ⭐ 唯一监听 completed 的地方
|
||||
_subscriptions.add(
|
||||
player.stream.completed.listen((_) {
|
||||
_onPlaybackCompleted();
|
||||
@@ -279,15 +282,23 @@ class AudioService extends ChangeNotifier {
|
||||
_subscriptions.clear();
|
||||
}
|
||||
|
||||
// ⭐ 防重入
|
||||
void _onPlaybackCompleted() {
|
||||
if (_queue.isEmpty) return;
|
||||
|
||||
if (_playMode == PlayMode.repeatOne) {
|
||||
_playCurrent();
|
||||
if (_handlingCompletion) {
|
||||
debugPrint('⚠️ [service] completed ignored: already handling');
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
_handlingCompletion = true;
|
||||
try {
|
||||
if (_queue.isEmpty) return;
|
||||
if (_playMode == PlayMode.repeatOne) {
|
||||
_playCurrent();
|
||||
return;
|
||||
}
|
||||
next();
|
||||
} finally {
|
||||
_handlingCompletion = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user