fix(alarm): anchor the fade at alarm time and defer the override to first audio
On-device logcat from the latest test showed two defects the previous design created. The fade-in was gated on the station reaching `reproduciendo`, and the stream took 18.7 seconds to buffer: the ring sat frozen at 5% the whole time and the configured fade seconds only started counting afterwards. And the stream override was raised during pre-start, so the ExoPlayer AudioTrack spin-up — which runs at gain 1.0 for an instant before the player gain lands — blasted at the configured ring level, heard as "starts directly at the alarm volume". The ramp is now anchored at alarm time: it starts when the screen starts, buffering just joins it at the elapsed level, and the fade duration means seconds-from-alarm. _iniciarFadeIn is single-start so the handoff confirmation and fallback paths can no longer restart an in-progress ramp from 5%. The stream override moved from the app-side pre-start into the screen and is raised only when audio is actually about to flow (first `reproduciendo`, the already-playing branch, or right before the fallback WAV plays), so track spin-up happens under the user's original low volume and the blast is physically impossible. Exit teardown restores the device stream before resetting the player gain, removing the brief exit blip seen in the capture.
This commit is contained in:
+6
-15
@@ -374,21 +374,12 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal> {
|
||||
}
|
||||
|
||||
Future<void> _prearrancarAudioAlarma(AlarmaMusical alarma) async {
|
||||
// Must run FIRST, before any early return: the override needs to be in
|
||||
// effect for the whole ring, including fallback-WAV-only alarms that
|
||||
// never reach the station-playback branch below (Requirement:
|
||||
// Ring-scoped device-volume override).
|
||||
//
|
||||
// The media stream is capped at the alarm's CONFIGURED volume, not the
|
||||
// device max: this makes the ring independent of the device's own volume
|
||||
// (audible even at 0) while keeping "50%" meaning 50% of the phone's
|
||||
// maximum. The player then ramps from ~5% up to full under this cap, so
|
||||
// the perceived peak is exactly the configured fraction of max, reached
|
||||
// gradually — not the device-relative level, and not a full-blast max.
|
||||
await context.read<EstadoAlarmas>().android.forzarVolumenMediaParaAlarma(
|
||||
alarma.volumen.clamp(0.0, 1.0),
|
||||
);
|
||||
if (!mounted) return;
|
||||
// The ring-scoped stream override is NOT raised here anymore: the ringing
|
||||
// screen owns it and raises it only when audio is actually about to be
|
||||
// audible (first `reproduciendo`, or right before the fallback WAV
|
||||
// plays). Raising it during pre-start let the ExoPlayer track spin-up —
|
||||
// which briefly runs at gain 1.0 — blast at the ring level; under the
|
||||
// user's original stream volume that spin-up is inaudible.
|
||||
final emisora = alarma.emisora;
|
||||
if (emisora == null) return;
|
||||
final radio = context.read<EstadoRadio>();
|
||||
|
||||
Reference in New Issue
Block a user