diff --git a/lib/servicios/servicio_audio.dart b/lib/servicios/servicio_audio.dart index 8265da8..1c11424 100644 --- a/lib/servicios/servicio_audio.dart +++ b/lib/servicios/servicio_audio.dart @@ -1253,6 +1253,26 @@ class PluriWaveAudioHandler extends BaseAudioHandler _cambiandoFuente = false; _revisionFuente++; await _player.stop(); + // Publish `idle` OURSELVES rather than trusting the player to emit it. + // `just_audio`'s `playerStateStream` is `.distinct()` over a value-equal + // `PlayerState`, so a stop landing on an already-idle player (a station + // change stopped before its native init finished pushing `loading`) + // emits NOTHING. Combined with the source-change mask above — which + // WRITES `loading` into `playbackState` rather than filtering at read + // time — that would leave the state stuck at `loading` forever: + // `audio_service` only tears the service down on a non-idle -> idle + // transition (`audio_service.dart:1131-1136`), so the notification would + // survive as an unkillable "cargando" with a dead Stop button. Strictly + // worse than the bug this branch fixes. Additive and idempotent: when + // the player DOES emit its own `idle`, this simply lands first and the + // duplicate is a no-op transition. + playbackState.add( + playbackState.value.copyWith( + processingState: AudioProcessingState.idle, + playing: false, + errorMessage: null, + ), + ); emisoraActual = null; mediaItem.add(null); await super.stop();