后台连续播放 + MediaItem + 播放状态 + 实时进度 + 系统 seek + seek 后继续实时更新均已正常达成目标

This commit is contained in:
2026-08-23 19:03:49 +08:00
parent be49823b60
commit c3271b07f1
+22 -13
View File
@@ -81,20 +81,29 @@ class AudioPlayerHandler extends audio_service.BaseAudioHandler {
void _publishStateOnly() {
final current = playbackState.value;
// ⭐ 使用类成员 _currentPosition,不再重复声明
debugPrint(
'📡 [publishStateOnly] position=$_currentPosition, playing=${current.playing}');
playbackState.add(audio_service.PlaybackState(
controls: current.controls.isNotEmpty
? current.controls
: _state.playbackState.controls,
processingState: _state.playbackState.processingState,
playing: current.playing,
androidCompactActionIndices: current.androidCompactActionIndices,
updatePosition: _currentPosition, // ⭐ 尝试加上
updateTime: DateTime.now(),
));
debugPrint(
'📡 [publishStateOnly] position=$_currentPosition, playing=${current.playing}',
);
playbackState.add(
audio_service.PlaybackState(
controls: current.controls.isNotEmpty
? current.controls
: _state.playbackState.controls,
processingState: _state.playbackState.processingState,
playing: current.playing,
androidCompactActionIndices: current.androidCompactActionIndices,
// ⭐ 声明支持 seek
systemActions: const {
audio_service.MediaAction.seek,
},
updatePosition: _currentPosition,
updateTime: DateTime.now(),
),
);
}
void _updateMediaItem({