Compare commits
1 Commits
feature/fi
...
feature/vi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6dad82e8c |
@@ -1,5 +1,11 @@
|
||||
# Changelog — PluriWave
|
||||
|
||||
## [0.5.0] — 2026-04-04
|
||||
|
||||
### Añadido
|
||||
- **VisualizadorAudio** — visualizador de barras animadas en `PantallaReproductor`. 24 barras verticales con movimiento orgánico pseudo-aleatorio (combinación de ondas seno con fases distintas). Se activa al reproducir y decae suavemente al parar. Sin FFT real ni permisos de micrófono — animación simulada visualmente equivalente a las apps de streaming.
|
||||
- **IndicadorReproduccion** — versión compacta de 3 barras para el `MiniReproductor`. Reemplaza el icono estático de radio y pulsa mientras hay audio activo.
|
||||
|
||||
## [0.4.0] — 2026-04-04
|
||||
|
||||
### Añadido
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
android:label="PluriWave"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
android:roundIcon="@mipmap/ic_launcher_round">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
network_security_config.xml
|
||||
Permite tráfico HTTP cleartext para streams de radio que no soporten HTTPS.
|
||||
Fix para: "Cleartext HTTP traffic to [host] not permitted" en ExoPlayer.
|
||||
-->
|
||||
<network-security-config>
|
||||
<!-- Permitir HTTP cleartext para streams de radio -->
|
||||
<base-config cleartextTrafficPermitted="true">
|
||||
<trust-anchors>
|
||||
<!-- Certificados del sistema (CA reconocidas) -->
|
||||
<certificates src="system"/>
|
||||
<!-- Certificados de usuario (para desarrollo) -->
|
||||
<certificates src="user"/>
|
||||
</trust-anchors>
|
||||
</base-config>
|
||||
</network-security-config>
|
||||
@@ -39,21 +39,6 @@ class EstadoRadio extends ChangeNotifier {
|
||||
EstadoRadio() {
|
||||
timer = ServicioTimer(audio);
|
||||
_init();
|
||||
_escucharErroresReproduccion();
|
||||
}
|
||||
|
||||
/// Escucha el stream de estado del audio y gestiona errores de reproducción
|
||||
/// de forma centralizada: cancela el timer y notifica al usuario.
|
||||
void _escucharErroresReproduccion() {
|
||||
audio.estadoStream.listen((estado) {
|
||||
if (estado == EstadoReproduccion.error) {
|
||||
// Cancelar el timer si estaba activo — no debe contar sin audio
|
||||
if (timer.activo) {
|
||||
timer.cancelar();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<Emisora> get populares => _populares;
|
||||
@@ -134,19 +119,7 @@ class EstadoRadio extends ChangeNotifier {
|
||||
await cambiarPresetEcualizador(preset, guardPorEmisora: false);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
// La reproducción falló: cancelar el timer para evitar estado inconsistente
|
||||
// (el timer no debe contar si no hay audio reproduciéndose)
|
||||
if (timer.activo) {
|
||||
timer.cancelar();
|
||||
}
|
||||
// Emitir mensaje claro al usuario con el nombre de la emisora
|
||||
final mensajeError = e.toString().replaceFirst('Exception: ', '');
|
||||
_errorController.add(
|
||||
mensajeError.isNotEmpty && mensajeError != 'Exception'
|
||||
? mensajeError
|
||||
: 'No se puede reproducir "${emisora.nombre}"',
|
||||
);
|
||||
notifyListeners();
|
||||
_errorController.add('No se puede reproducir "${emisora.nombre}"');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../widgets/visualizador_audio.dart';
|
||||
import '../estado/estado_radio.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
import '../servicios/servicio_audio.dart';
|
||||
@@ -146,6 +147,14 @@ class _PantallaReproductorState extends State<PantallaReproductor>
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
).animate().fadeIn(delay: 250.ms),
|
||||
const SizedBox(height: 16),
|
||||
// Visualizador de audio
|
||||
VisualizadorAudio(
|
||||
estadoStream: estado.estadoStream,
|
||||
barras: 24,
|
||||
color: theme.colorScheme.primary,
|
||||
altura: 48,
|
||||
).animate().fadeIn(delay: 280.ms),
|
||||
const Spacer(flex: 2),
|
||||
// Controles
|
||||
_Controles(
|
||||
@@ -191,7 +200,6 @@ class _Artwork extends StatelessWidget {
|
||||
builder: (context, snapshot) {
|
||||
final reproduciendo = snapshot.data == EstadoReproduccion.reproduciendo;
|
||||
final cargando = snapshot.data == EstadoReproduccion.cargando;
|
||||
final hayError = snapshot.data == EstadoReproduccion.error;
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
@@ -199,15 +207,7 @@ class _Artwork extends StatelessWidget {
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: hayError
|
||||
? [
|
||||
BoxShadow(
|
||||
color: theme.colorScheme.error.withValues(alpha: 0.25),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
]
|
||||
: reproduciendo
|
||||
boxShadow: reproduciendo
|
||||
? [
|
||||
BoxShadow(
|
||||
color: theme.colorScheme.primary.withValues(alpha: 0.4),
|
||||
@@ -229,15 +229,12 @@ class _Artwork extends StatelessWidget {
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Logo / imagen
|
||||
// errorWidget captura HandshakeException (cert autofirmado)
|
||||
// y cualquier fallo de red en artwork. El error queda
|
||||
// contenido aquí — no se propaga ni rompe el reproductor.
|
||||
if (emisora.favicon != null && emisora.favicon!.isNotEmpty)
|
||||
CachedNetworkImage(
|
||||
imageUrl: emisora.favicon!,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (_, __) => _shimmer(theme),
|
||||
errorWidget: (_, url, error) => _iconoFallback(theme),
|
||||
errorWidget: (_, __, ___) => _iconoFallback(theme),
|
||||
)
|
||||
else
|
||||
_iconoFallback(theme),
|
||||
@@ -249,18 +246,6 @@ class _Artwork extends StatelessWidget {
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
),
|
||||
),
|
||||
// Overlay de error de reproducción
|
||||
if (hayError)
|
||||
Container(
|
||||
color: Colors.black54,
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.wifi_off_rounded,
|
||||
size: 56,
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -334,35 +319,6 @@ class _Controles extends StatelessWidget {
|
||||
final s = snapshot.data ?? EstadoReproduccion.detenido;
|
||||
final reproduciendo = s == EstadoReproduccion.reproduciendo;
|
||||
final cargando = s == EstadoReproduccion.cargando;
|
||||
final hayError = s == EstadoReproduccion.error;
|
||||
|
||||
// En estado de error: mostrar mensaje y botón de reintento
|
||||
if (hayError) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline_rounded,
|
||||
size: 40,
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'No se puede reproducir esta radio',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FilledButton.tonalIcon(
|
||||
icon: const Icon(Icons.refresh_rounded, size: 18),
|
||||
label: const Text('Reintentar'),
|
||||
onPressed: () => estado.reproducir(emisora),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:audio_service/audio_service.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
@@ -28,9 +26,6 @@ class ServicioAudio {
|
||||
|
||||
Stream<EstadoReproduccion> get estadoStream =>
|
||||
_handler.playbackState.map((s) {
|
||||
if (s.processingState == AudioProcessingState.error) {
|
||||
return EstadoReproduccion.error;
|
||||
}
|
||||
if (s.processingState == AudioProcessingState.loading ||
|
||||
s.processingState == AudioProcessingState.buffering) {
|
||||
return EstadoReproduccion.cargando;
|
||||
@@ -131,83 +126,6 @@ class PluriWaveAudioHandler extends BaseAudioHandler with SeekHandler {
|
||||
_player.bufferedPositionStream.listen((pos) {
|
||||
playbackState.add(playbackState.value.copyWith(bufferedPosition: pos));
|
||||
});
|
||||
|
||||
// ── Escuchar errores de ExoPlayer ─────────────────────────────────────
|
||||
// Captura todos los PlaybackException: TYPE_SOURCE (HTTP cleartext,
|
||||
// certificado inválido, 404), TYPE_UNEXPECTED, timeout de conexión, etc.
|
||||
_player.playbackEventStream.listen(
|
||||
(_) {},
|
||||
onError: (Object error, StackTrace stackTrace) {
|
||||
_gestionarErrorReproduccion(error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Gestiona cualquier error de reproducción de ExoPlayer de forma
|
||||
/// controlada: emite estado de error al UI y resetea la reproducción.
|
||||
void _gestionarErrorReproduccion(Object error) {
|
||||
String mensaje;
|
||||
String codigoLog;
|
||||
|
||||
if (error is PlayerException) {
|
||||
codigoLog = 'PlayerException(code=${error.code}): ${error.message}';
|
||||
mensaje = _mensajeAmigable(error);
|
||||
} else {
|
||||
codigoLog = 'Error desconocido: $error';
|
||||
mensaje = 'Error de reproducción';
|
||||
}
|
||||
|
||||
developer.log(
|
||||
'[PluriWave] Error reproducción: $codigoLog',
|
||||
name: 'ServicioAudio',
|
||||
level: 900, // warning
|
||||
);
|
||||
|
||||
// Emitir estado de error al UI (incluye mensaje legible)
|
||||
playbackState.add(playbackState.value.copyWith(
|
||||
processingState: AudioProcessingState.error,
|
||||
playing: false,
|
||||
errorMessage: mensaje,
|
||||
));
|
||||
|
||||
// Resetear el player a estado idle limpio (sin lanzar otra excepción)
|
||||
_player.stop().catchError((_) {});
|
||||
}
|
||||
|
||||
/// Traduce códigos de error de ExoPlayer a mensajes para el usuario.
|
||||
String _mensajeAmigable(PlayerException e) {
|
||||
final code = e.code;
|
||||
|
||||
// ERROR_CODE_IO_* — problemas de red/fuente
|
||||
if (code >= 2000 && code < 3000) {
|
||||
if (code == 2001) return 'Sin conexión a internet';
|
||||
if (code == 2002) return 'La URL de la radio no es válida';
|
||||
if (code == 2003) return 'La radio no está disponible (error 404)';
|
||||
if (code == 2004) return 'Tiempo de espera agotado al conectar';
|
||||
return 'No se puede conectar a la radio';
|
||||
}
|
||||
|
||||
// ERROR_CODE_PARSING_* — formato de stream no soportado
|
||||
if (code >= 3000 && code < 4000) {
|
||||
return 'Formato de stream no compatible';
|
||||
}
|
||||
|
||||
// ERROR_CODE_DECODING_* — error de decodificación
|
||||
if (code >= 4000 && code < 5000) {
|
||||
return 'Error al decodificar el stream de audio';
|
||||
}
|
||||
|
||||
// TYPE_SOURCE — error en la fuente (HTTP cleartext, cert, etc.)
|
||||
// En just_audio suele mapearse como code=-1 o message con "Cleartext"
|
||||
final msg = e.message ?? '';
|
||||
if (msg.contains('Cleartext') || msg.contains('cleartext')) {
|
||||
return 'Esta radio usa HTTP sin cifrar (no permitido)';
|
||||
}
|
||||
if (msg.contains('CERTIFICATE') || msg.contains('HandshakeException')) {
|
||||
return 'Certificado SSL inválido en la radio';
|
||||
}
|
||||
|
||||
return 'No se puede reproducir esta radio';
|
||||
}
|
||||
|
||||
AudioProcessingState _mapProcState(ProcessingState state) {
|
||||
@@ -221,30 +139,19 @@ class PluriWaveAudioHandler extends BaseAudioHandler with SeekHandler {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> playMediaItem(MediaItem mediaItem) async {
|
||||
this.mediaItem.add(mediaItem);
|
||||
Future<void> playMediaItem(MediaItem item) async {
|
||||
mediaItem.add(item);
|
||||
try {
|
||||
await _player.stop();
|
||||
await _player.setUrl(mediaItem.id);
|
||||
await _player.setUrl(item.id);
|
||||
await _player.play();
|
||||
// Habilitar ecualizador tras reproducir (necesita audio activo)
|
||||
await _activarEcualizador();
|
||||
} on PlayerException catch (e) {
|
||||
// El error ya llega por playbackEventStream.onError, pero también
|
||||
// lo capturamos aquí para asegurarnos de emitir el estado de error
|
||||
// y propagarlo como excepción (para que EstadoRadio muestre el mensaje).
|
||||
_gestionarErrorReproduccion(e);
|
||||
throw Exception(_mensajeAmigable(e));
|
||||
} on Exception catch (e) {
|
||||
developer.log(
|
||||
'[PluriWave] Error inesperado en playMediaItem: $e',
|
||||
name: 'ServicioAudio',
|
||||
level: 900,
|
||||
);
|
||||
playbackState.add(playbackState.value.copyWith(
|
||||
processingState: AudioProcessingState.error,
|
||||
playing: false,
|
||||
errorMessage: 'Error inesperado al reproducir',
|
||||
errorMessage: e.message ?? 'Error de reproducción',
|
||||
errorCode: e.code,
|
||||
));
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
||||
import '../estado/estado_radio.dart';
|
||||
import '../pantallas/pantalla_reproductor.dart';
|
||||
import '../servicios/servicio_audio.dart';
|
||||
import 'visualizador_audio.dart';
|
||||
|
||||
/// Barra inferior persistente con controles básicos de reproducción.
|
||||
/// Toca la barra para abrir PantallaReproductor completa.
|
||||
@@ -33,16 +34,16 @@ class MiniReproductor extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
// Logo
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
color: theme.colorScheme.primaryContainer,
|
||||
child: Icon(Icons.radio,
|
||||
size: 22,
|
||||
color: theme.colorScheme.onPrimaryContainer),
|
||||
// Indicador de reproducción (mini visualizador)
|
||||
SizedBox(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: Center(
|
||||
child: IndicadorReproduccion(
|
||||
estadoStream: estado.estadoStream,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
@@ -91,17 +92,6 @@ class MiniReproductor extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
// En estado error: mostrar icono de reintento
|
||||
if (s == EstadoReproduccion.error) {
|
||||
final emisora = estado.emisoraActual;
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
tooltip: 'Reintentar',
|
||||
onPressed: emisora != null
|
||||
? () => estado.reproducir(emisora)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
icon: Icon(
|
||||
s == EstadoReproduccion.reproduciendo
|
||||
|
||||
241
lib/widgets/visualizador_audio.dart
Normal file
241
lib/widgets/visualizador_audio.dart
Normal file
@@ -0,0 +1,241 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../servicios/servicio_audio.dart';
|
||||
|
||||
/// Visualizador de audio animado para la pantalla del reproductor.
|
||||
///
|
||||
/// Muestra barras verticales que se animan con movimiento pseudo-aleatorio
|
||||
/// basado en ruido suavizado mientras la radio está reproduciéndose.
|
||||
/// Cuando está pausado/detenido, las barras se aplanan suavemente.
|
||||
///
|
||||
/// ### Implementación
|
||||
/// No usa FFT real (requeriría captura de micrófono con permisos).
|
||||
/// En cambio, usa un generador de movimiento orgánico con interpolación
|
||||
/// suavizada — el resultado visual es similar al de apps de streaming como
|
||||
/// Spotify o Apple Music en sus visualizadores de "en reproducción".
|
||||
///
|
||||
/// ### Uso
|
||||
/// ```dart
|
||||
/// VisualizadorAudio(
|
||||
/// estadoStream: estado.estadoStream,
|
||||
/// barras: 24,
|
||||
/// color: theme.colorScheme.primary,
|
||||
/// altura: 60,
|
||||
/// )
|
||||
/// ```
|
||||
class VisualizadorAudio extends StatefulWidget {
|
||||
final Stream<EstadoReproduccion> estadoStream;
|
||||
final int barras;
|
||||
final Color? color;
|
||||
final double altura;
|
||||
final double anchuraTotal;
|
||||
|
||||
const VisualizadorAudio({
|
||||
super.key,
|
||||
required this.estadoStream,
|
||||
this.barras = 20,
|
||||
this.color,
|
||||
this.altura = 48,
|
||||
this.anchuraTotal = double.infinity,
|
||||
});
|
||||
|
||||
@override
|
||||
State<VisualizadorAudio> createState() => _VisualizadorAudioState();
|
||||
}
|
||||
|
||||
class _VisualizadorAudioState extends State<VisualizadorAudio>
|
||||
with TickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late List<_BarraState> _barras;
|
||||
final _random = Random();
|
||||
bool _activo = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_barras = List.generate(
|
||||
widget.barras,
|
||||
(i) => _BarraState(
|
||||
fase: _random.nextDouble() * pi * 2,
|
||||
velocidad: 0.8 + _random.nextDouble() * 1.4,
|
||||
amplitud: 0.4 + _random.nextDouble() * 0.6,
|
||||
offset: _random.nextDouble() * 0.3,
|
||||
),
|
||||
);
|
||||
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 1),
|
||||
)..addListener(_actualizar);
|
||||
|
||||
widget.estadoStream.listen(_onEstado);
|
||||
}
|
||||
|
||||
void _onEstado(EstadoReproduccion estado) {
|
||||
final nuevoActivo = estado == EstadoReproduccion.reproduciendo ||
|
||||
estado == EstadoReproduccion.cargando;
|
||||
if (nuevoActivo == _activo) return;
|
||||
setState(() => _activo = nuevoActivo);
|
||||
if (nuevoActivo) {
|
||||
_controller.repeat();
|
||||
} else {
|
||||
_controller.forward(from: _controller.value).whenComplete(() {
|
||||
if (!_activo && mounted) _controller.stop();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _actualizar() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = widget.color ?? Theme.of(context).colorScheme.primary;
|
||||
final t = _controller.value * pi * 2;
|
||||
|
||||
return SizedBox(
|
||||
height: widget.altura,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final totalAncho = constraints.maxWidth == double.infinity
|
||||
? 300.0
|
||||
: constraints.maxWidth;
|
||||
final espaciado = totalAncho / widget.barras;
|
||||
final anchoBar = (espaciado * 0.55).clamp(2.0, 8.0);
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: List.generate(widget.barras, (i) {
|
||||
final b = _barras[i];
|
||||
final double altura;
|
||||
|
||||
if (_activo) {
|
||||
// Movimiento orgánico: combinación de senos con diferentes fases
|
||||
final onda1 = sin(t * b.velocidad + b.fase);
|
||||
final onda2 = sin(t * b.velocidad * 0.7 + b.fase * 1.3) * 0.5;
|
||||
final valor = ((onda1 + onda2 + 1.5) / 3.0).clamp(0.0, 1.0);
|
||||
altura = (b.offset + valor * b.amplitud) * widget.altura;
|
||||
} else {
|
||||
// Decaer suavemente a altura mínima
|
||||
final progreso = _controller.value;
|
||||
final alturaActual = b.alturaActual;
|
||||
b.alturaActual = alturaActual * (1 - progreso * 0.1);
|
||||
altura = b.alturaActual.clamp(2.0, widget.altura * 0.05);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: (espaciado - anchoBar) / 2),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 80),
|
||||
width: anchoBar,
|
||||
height: altura.clamp(2.0, widget.altura),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(
|
||||
alpha: _activo ? 0.7 + (altura / widget.altura) * 0.3 : 0.3,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(anchoBar / 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BarraState {
|
||||
final double fase;
|
||||
final double velocidad;
|
||||
final double amplitud;
|
||||
final double offset;
|
||||
double alturaActual;
|
||||
|
||||
_BarraState({
|
||||
required this.fase,
|
||||
required this.velocidad,
|
||||
required this.amplitud,
|
||||
required this.offset,
|
||||
}) : alturaActual = offset * 20;
|
||||
}
|
||||
|
||||
/// Versión compacta del visualizador — 5 barras, para uso en MiniReproductor
|
||||
/// o indicadores pequeños de "en reproducción".
|
||||
class IndicadorReproduccion extends StatefulWidget {
|
||||
final Stream<EstadoReproduccion> estadoStream;
|
||||
final Color? color;
|
||||
final double size;
|
||||
|
||||
const IndicadorReproduccion({
|
||||
super.key,
|
||||
required this.estadoStream,
|
||||
this.color,
|
||||
this.size = 16,
|
||||
});
|
||||
|
||||
@override
|
||||
State<IndicadorReproduccion> createState() => _IndicadorReproduccionState();
|
||||
}
|
||||
|
||||
class _IndicadorReproduccionState extends State<IndicadorReproduccion>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _ctrl;
|
||||
bool _reproduciendo = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ctrl = AnimationController(vsync: this, duration: const Duration(milliseconds: 600))
|
||||
..addListener(() => setState(() {}));
|
||||
widget.estadoStream.listen((s) {
|
||||
final rep = s == EstadoReproduccion.reproduciendo;
|
||||
if (rep == _reproduciendo) return;
|
||||
setState(() => _reproduciendo = rep);
|
||||
rep ? _ctrl.repeat(reverse: true) : _ctrl.stop();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = widget.color ??
|
||||
Theme.of(context).colorScheme.primary;
|
||||
if (!_reproduciendo) {
|
||||
return Icon(Icons.radio, size: widget.size,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant);
|
||||
}
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: List.generate(3, (i) {
|
||||
final alts = [0.5, 1.0, 0.7];
|
||||
final fases = [0.0, 0.3, 0.6];
|
||||
final h = ((sin(_ctrl.value * pi + fases[i]) + 1) / 2 * alts[i] + 0.2)
|
||||
.clamp(0.15, 1.0) * widget.size;
|
||||
return Container(
|
||||
width: widget.size * 0.2,
|
||||
height: h,
|
||||
margin: EdgeInsets.only(right: i < 2 ? widget.size * 0.1 : 0),
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,30 @@
|
||||
// Tests básicos de PluriWave.
|
||||
// El test de smoke original usaba MyApp (boilerplate de Flutter) que no
|
||||
// existe en este proyecto — corregido para usar PluriWaveApp.
|
||||
// Los tests de integración completos (audio, streaming) requieren un dispositivo.
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pluriwave/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Placeholder — tests de integración requieren dispositivo', (tester) async {
|
||||
// Los tests reales de reproducción de audio requieren un dispositivo físico
|
||||
// o emulador con soporte de audio. Este placeholder evita que el CI falle
|
||||
// por el test de smoke incorrecto del boilerplate original.
|
||||
expect(true, isTrue);
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user