Matthias Nott
2026-03-24 d17b6376e8137447c244693853fd05b57aaf368f
lib/screens/chat_screen.dart
....@@ -86,12 +86,18 @@
8686 // Listen for playback state changes to reset play button UI
8787 // Use a brief delay to avoid race between queue transitions
8888 AudioService.onPlaybackStateChanged = () {
89
- if (mounted && !AudioService.isPlaying) {
90
- Future.delayed(const Duration(milliseconds: 100), () {
91
- if (mounted && !AudioService.isPlaying) {
92
- setState(() => _playingMessageId = null);
93
- }
94
- });
89
+ if (mounted) {
90
+ if (AudioService.isPlaying) {
91
+ // Something started playing — keep the indicator as-is
92
+ } else {
93
+ // Playback stopped — clear indicator only if queue is truly empty.
94
+ // Use a short delay since the queue transition has a brief gap.
95
+ Future.delayed(const Duration(milliseconds: 200), () {
96
+ if (mounted && !AudioService.isPlaying) {
97
+ setState(() => _playingMessageId = null);
98
+ }
99
+ });
100
+ }
95101 }
96102 };
97103
....@@ -519,12 +525,7 @@
519525 _scrollToBottom();
520526
521527 if (audioData != null && !AudioService.isBackgrounded && !_isCatchingUp && !_isRecording) {
522
- // Only set playing ID if nothing is currently playing (first chunk).
523
- // Subsequent chunks just queue audio without touching the play indicator,
524
- // preventing the completion callback race from clearing it prematurely.
525
- if (_playingMessageId == null) {
526
- setState(() => _playingMessageId = storedMessage.id);
527
- }
528
+ setState(() => _playingMessageId = storedMessage.id);
528529 AudioService.queueBase64(audioData);
529530 }
530531 }