通知中心全部控制逻辑已达成,即将进入后台与播放歌曲标题推送的优化
This commit is contained in:
@@ -17,23 +17,23 @@ class PlaybackStateManager {
|
||||
Duration get duration => _duration;
|
||||
|
||||
// ⭐ 核心改动:使用 playPause 替代 play/pause 分离
|
||||
// lib/audio/playback_state_manager.dart
|
||||
audio_service.PlaybackState get playbackState {
|
||||
// ⭐ 固定使用 playPause,不再动态切换
|
||||
final playControl = audio_service.MediaControl(
|
||||
androidIcon: _playing ? 'drawable/ic_pause' : 'drawable/ic_play',
|
||||
label: _playing ? '暂停' : '播放',
|
||||
action: audio_service.MediaAction.playPause, // 固定
|
||||
action: audio_service.MediaAction.playPause,
|
||||
);
|
||||
|
||||
final controls = [
|
||||
audio_service.MediaControl(
|
||||
androidIcon: 'drawable/ic_previous',
|
||||
androidIcon: 'drawable/ic_previous', // 上一首
|
||||
label: '上一曲',
|
||||
action: audio_service.MediaAction.skipToPrevious,
|
||||
),
|
||||
playControl,
|
||||
audio_service.MediaControl(
|
||||
androidIcon: 'drawable/ic_next',
|
||||
androidIcon: 'drawable/ic_next', // 下一首
|
||||
label: '下一曲',
|
||||
action: audio_service.MediaAction.skipToNext,
|
||||
),
|
||||
@@ -42,10 +42,9 @@ class PlaybackStateManager {
|
||||
return audio_service.PlaybackState(
|
||||
controls: controls,
|
||||
processingState: audio_service.AudioProcessingState.ready,
|
||||
playing: _playing, // ⭐ 这里才是真正的播放状态,通知栏会根据它显示正确的图标
|
||||
androidCompactActionIndices: const [0, 1, 2],
|
||||
playing: _playing,
|
||||
androidCompactActionIndices: const [0, 1, 2], // 显示全部三个
|
||||
updateTime: DateTime.now(),
|
||||
//extras: {'_refresh': DateTime.now().millisecondsSinceEpoch},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user