Compare commits
4 Commits
9aa881342d
...
4764266a1a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4764266a1a | ||
| 7044cc0b2a | |||
|
|
ac5ab2316f | ||
|
|
81db383a47 |
28
CHANGELOG.md
@@ -1,5 +1,33 @@
|
|||||||
# Changelog — PluriWave
|
# Changelog — PluriWave
|
||||||
|
|
||||||
|
## [0.4.0] — 2026-04-04
|
||||||
|
|
||||||
|
### Añadido
|
||||||
|
- **PantallaReproductor** — pantalla completa del reproductor. Accesible tocando MiniReproductor o cualquier emisora. Incluye: artwork/logo grande con sombra animada al reproducir, nombre + chips info (país, idioma), codec/bitrate, controles play/pause/stop con indicador "en vivo", botón favorito (toggle), widget de timer (iniciar/cancelar desde la pantalla), animación de entrada slide-up. Transición pageRoute desde cualquier pantalla.
|
||||||
|
- **PantallaAjustes** — pantalla de ajustes básica (tab nuevo en NavigationBar). Muestra estado del sistema (filtro emisoras, audio background), conteo de favoritos, preview de features próximas (Export/Import, radio personalizada, ecualizador).
|
||||||
|
- **MiniReproductor** — ahora es tappable: toca la barra para abrir PantallaReproductor.
|
||||||
|
- **NavigationBar** — añadido tab "Ajustes" (4 destinos: Inicio/Buscar/Favoritos/Ajustes).
|
||||||
|
|
||||||
|
## [0.3.0] — 2026-04-04
|
||||||
|
|
||||||
|
### Fixes (prioridad alta — petición WhikY)
|
||||||
|
|
||||||
|
- **Audio en background** — `ServicioAudio` refactorizado para delegar toda la reproducción a `PluriWaveAudioHandler` (audio_service). La notificación foreground de Android mantiene el audio vivo al apagar pantalla. Handler inicializado en `main.dart` con `AudioService.init()` y registrado globalmente. `onTaskRemoved` libera recursos al cerrar la app. `mediaItem` propagado con nombre, artista y artwork de la emisora.
|
||||||
|
- **Filtrar emisoras rotas** — `ServicioRadio` añade `lastcheckok=1` en todas las peticiones a la API. Solo se devuelven emisoras verificadas como funcionales por Radio Browser.
|
||||||
|
- **Errores como SnackBar** — `EstadoRadio` emite errores de reproducción y búsqueda por `errorStream` (StreamController broadcast). `_PaginaPrincipalState.didChangeDependencies` suscribe al stream y muestra `SnackBar` flotante de 3 segundos. Los errores de carga de lista siguen como banner inline (no bloquean la UI).
|
||||||
|
- **Icono de app** — Generado con Stable Diffusion XL: diseño morado, ondas de radio blancas, estilo Material You. Todos los tamaños Android generados (mdpi/hdpi/xhdpi/xxhdpi/xxxhdpi, 48-192px). `ic_launcher_round` añadido. `android:roundIcon` en AndroidManifest.
|
||||||
|
|
||||||
|
### Ficheros modificados
|
||||||
|
| Fichero | Cambio |
|
||||||
|
|---|---|
|
||||||
|
| `lib/main.dart` | `AudioService.init()` + `registrarHandler()` |
|
||||||
|
| `lib/servicios/servicio_audio.dart` | Arquitectura background completa |
|
||||||
|
| `lib/servicios/servicio_radio.dart` | `lastcheckok=1` en todas las peticiones |
|
||||||
|
| `lib/estado/estado_radio.dart` | `errorStream` en lugar de campo `_error` |
|
||||||
|
| `lib/app.dart` | Listener `errorStream` → SnackBar + theme SnackBar |
|
||||||
|
| `android/app/src/main/AndroidManifest.xml` | `roundIcon` |
|
||||||
|
| `android/app/src/main/res/mipmap-*/` | Iconos generados (5 densidades) |
|
||||||
|
|
||||||
## [0.2.0] — 2026-04-04
|
## [0.2.0] — 2026-04-04
|
||||||
|
|
||||||
### Añadido
|
### Añadido
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
<application
|
<application
|
||||||
android:label="PluriWave"
|
android:label="PluriWave"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 3.2 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 2.0 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 4.6 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 8.5 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/images/ic_launcher_source.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
73
lib/app.dart
@@ -5,6 +5,7 @@ import 'estado/estado_radio.dart';
|
|||||||
import 'pantallas/pantalla_inicio.dart';
|
import 'pantallas/pantalla_inicio.dart';
|
||||||
import 'pantallas/pantalla_buscar.dart';
|
import 'pantallas/pantalla_buscar.dart';
|
||||||
import 'pantallas/pantalla_favoritos.dart';
|
import 'pantallas/pantalla_favoritos.dart';
|
||||||
|
import 'pantallas/pantalla_ajustes.dart';
|
||||||
import 'widgets/mini_reproductor.dart';
|
import 'widgets/mini_reproductor.dart';
|
||||||
|
|
||||||
class PluriWaveApp extends StatelessWidget {
|
class PluriWaveApp extends StatelessWidget {
|
||||||
@@ -27,7 +28,7 @@ class PluriWaveApp extends StatelessWidget {
|
|||||||
|
|
||||||
ThemeData _buildTheme(Brightness brightness) {
|
ThemeData _buildTheme(Brightness brightness) {
|
||||||
final colorScheme = ColorScheme.fromSeed(
|
final colorScheme = ColorScheme.fromSeed(
|
||||||
seedColor: const Color(0xFF6750A4), // Morado Material You
|
seedColor: const Color(0xFF6750A4),
|
||||||
brightness: brightness,
|
brightness: brightness,
|
||||||
);
|
);
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
@@ -41,6 +42,10 @@ class PluriWaveApp extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
color: colorScheme.surfaceContainerLow,
|
color: colorScheme.surfaceContainerLow,
|
||||||
),
|
),
|
||||||
|
snackBarTheme: SnackBarThemeData(
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +64,7 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal> {
|
|||||||
PantallaInicio(),
|
PantallaInicio(),
|
||||||
PantallaBuscar(),
|
PantallaBuscar(),
|
||||||
PantallaFavoritos(),
|
PantallaFavoritos(),
|
||||||
|
PantallaAjustes(),
|
||||||
];
|
];
|
||||||
|
|
||||||
static const _destinos = [
|
static const _destinos = [
|
||||||
@@ -77,21 +83,43 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal> {
|
|||||||
selectedIcon: Icon(Icons.favorite),
|
selectedIcon: Icon(Icons.favorite),
|
||||||
label: 'Favoritos',
|
label: 'Favoritos',
|
||||||
),
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.settings_outlined),
|
||||||
|
selectedIcon: Icon(Icons.settings),
|
||||||
|
label: 'Ajustes',
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
context.read<EstadoRadio>().errorStream.listen((msg) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(msg),
|
||||||
|
duration: const Duration(seconds: 3),
|
||||||
|
action: SnackBarAction(label: 'OK', onPressed: () {}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: _indice == 3
|
||||||
title: const Text('PluriWave'),
|
? null // PantallaAjustes tiene su propio AppBar
|
||||||
actions: [
|
: AppBar(
|
||||||
IconButton(
|
title: const Text('PluriWave'),
|
||||||
icon: const Icon(Icons.bedtime_outlined),
|
actions: [
|
||||||
tooltip: 'Timer de sueño',
|
IconButton(
|
||||||
onPressed: () => _mostrarTimerDialog(context),
|
icon: const Icon(Icons.bedtime_outlined),
|
||||||
),
|
tooltip: 'Timer de sueño',
|
||||||
],
|
onPressed: () => _mostrarTimerDialog(context),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
body: _paginas[_indice],
|
body: _paginas[_indice],
|
||||||
bottomNavigationBar: Column(
|
bottomNavigationBar: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -125,12 +153,15 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal> {
|
|||||||
stream: estado.timer.tiempoRestanteStream,
|
stream: estado.timer.tiempoRestanteStream,
|
||||||
builder: (ctx, snap) {
|
builder: (ctx, snap) {
|
||||||
final t = snap.data ?? Duration.zero;
|
final t = snap.data ?? Duration.zero;
|
||||||
|
final h = t.inHours;
|
||||||
final m = t.inMinutes.remainder(60).toString().padLeft(2, '0');
|
final m = t.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||||
final s = t.inSeconds.remainder(60).toString().padLeft(2, '0');
|
final s = t.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text('${t.inHours > 0 ? "${t.inHours}h " : ""}${m}m ${s}s',
|
Text(
|
||||||
style: Theme.of(ctx).textTheme.headlineMedium),
|
'${h > 0 ? "${h}h " : ""}${m}m ${s}s',
|
||||||
|
style: Theme.of(ctx).textTheme.headlineMedium,
|
||||||
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
FilledButton.tonal(
|
FilledButton.tonal(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -146,13 +177,15 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal> {
|
|||||||
else
|
else
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
children: [15, 30, 60, 90].map((min) => ActionChip(
|
children: [15, 30, 60, 90]
|
||||||
label: Text('$min min'),
|
.map((min) => ActionChip(
|
||||||
onPressed: () {
|
label: Text('$min min'),
|
||||||
estado.iniciarTimer(min);
|
onPressed: () {
|
||||||
Navigator.pop(ctx);
|
estado.iniciarTimer(min);
|
||||||
},
|
Navigator.pop(ctx);
|
||||||
)).toList(),
|
},
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import '../modelos/emisora.dart';
|
import '../modelos/emisora.dart';
|
||||||
import '../servicios/servicio_audio.dart';
|
import '../servicios/servicio_audio.dart';
|
||||||
@@ -7,13 +8,18 @@ import '../servicios/servicio_timer.dart';
|
|||||||
|
|
||||||
/// Estado global de la app con ChangeNotifier (Provider).
|
/// Estado global de la app con ChangeNotifier (Provider).
|
||||||
///
|
///
|
||||||
/// Centraliza: reproductoor, favoritos, búsqueda, timer.
|
/// Errores de reproducción se emiten por [errorStream] para mostrar como
|
||||||
|
/// SnackBar — no bloquean la UI.
|
||||||
class EstadoRadio extends ChangeNotifier {
|
class EstadoRadio extends ChangeNotifier {
|
||||||
final ServicioAudio audio = ServicioAudio();
|
final ServicioAudio audio = ServicioAudio();
|
||||||
final ServicioFavoritos favoritos = ServicioFavoritos();
|
final ServicioFavoritos favoritos = ServicioFavoritos();
|
||||||
final ServicioRadio radio = ServicioRadio();
|
final ServicioRadio radio = ServicioRadio();
|
||||||
late final ServicioTimer timer;
|
late final ServicioTimer timer;
|
||||||
|
|
||||||
|
// Errores de reproducción → SnackBar en el UI
|
||||||
|
final _errorController = StreamController<String>.broadcast();
|
||||||
|
Stream<String> get errorStream => _errorController.stream;
|
||||||
|
|
||||||
List<Emisora> _populares = [];
|
List<Emisora> _populares = [];
|
||||||
List<Emisora> _tendencias = [];
|
List<Emisora> _tendencias = [];
|
||||||
List<Emisora> _resultadosBusqueda = [];
|
List<Emisora> _resultadosBusqueda = [];
|
||||||
@@ -21,7 +27,7 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
|
|
||||||
bool _cargandoPopulares = false;
|
bool _cargandoPopulares = false;
|
||||||
bool _cargandoBusqueda = false;
|
bool _cargandoBusqueda = false;
|
||||||
String? _error;
|
String? _errorCarga; // solo para errores de carga de lista (banner estático)
|
||||||
|
|
||||||
EstadoRadio() {
|
EstadoRadio() {
|
||||||
timer = ServicioTimer(audio);
|
timer = ServicioTimer(audio);
|
||||||
@@ -34,7 +40,7 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
List<Emisora> get listaFavoritos => _listafavoritos;
|
List<Emisora> get listaFavoritos => _listafavoritos;
|
||||||
bool get cargandoPopulares => _cargandoPopulares;
|
bool get cargandoPopulares => _cargandoPopulares;
|
||||||
bool get cargandoBusqueda => _cargandoBusqueda;
|
bool get cargandoBusqueda => _cargandoBusqueda;
|
||||||
String? get error => _error;
|
String? get error => _errorCarga;
|
||||||
Emisora? get emisoraActual => audio.emisoraActual;
|
Emisora? get emisoraActual => audio.emisoraActual;
|
||||||
Stream<EstadoReproduccion> get estadoStream => audio.estadoStream;
|
Stream<EstadoReproduccion> get estadoStream => audio.estadoStream;
|
||||||
|
|
||||||
@@ -47,7 +53,7 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> cargarPopulares() async {
|
Future<void> cargarPopulares() async {
|
||||||
_cargandoPopulares = true;
|
_cargandoPopulares = true;
|
||||||
_error = null;
|
_errorCarga = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
final results = await Future.wait([
|
final results = await Future.wait([
|
||||||
@@ -57,7 +63,7 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
_populares = results[0];
|
_populares = results[0];
|
||||||
_tendencias = results[1];
|
_tendencias = results[1];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_error = 'Error al cargar emisoras: $e';
|
_errorCarga = 'Sin conexión a la API de radio';
|
||||||
} finally {
|
} finally {
|
||||||
_cargandoPopulares = false;
|
_cargandoPopulares = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -86,7 +92,8 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
tag: tag,
|
tag: tag,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_error = 'Error en búsqueda: $e';
|
// Error de búsqueda → toast, no bloquear pantalla
|
||||||
|
_errorController.add('Error en la búsqueda. Comprueba tu conexión.');
|
||||||
} finally {
|
} finally {
|
||||||
_cargandoBusqueda = false;
|
_cargandoBusqueda = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -99,8 +106,8 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
radio.registrarClick(emisora.uuid); // fire & forget
|
radio.registrarClick(emisora.uuid); // fire & forget
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_error = 'No se puede reproducir esta emisora';
|
// Error de reproducción → SnackBar, no pintar en medio de la UI
|
||||||
notifyListeners();
|
_errorController.add('No se puede reproducir "${emisora.nombre}"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +136,7 @@ class EstadoRadio extends ChangeNotifier {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_errorController.close();
|
||||||
audio.dispose();
|
audio.dispose();
|
||||||
timer.dispose();
|
timer.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
|
import 'package:audio_service/audio_service.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'app.dart';
|
import 'app.dart';
|
||||||
|
import 'servicios/servicio_audio.dart';
|
||||||
|
|
||||||
void main() {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// Inicializar audio_service para reproducción en background.
|
||||||
|
// El handler se registra globalmente para que ServicioAudio lo use.
|
||||||
|
final handler = await AudioService.init(
|
||||||
|
builder: () => PluriWaveAudioHandler(),
|
||||||
|
config: const AudioServiceConfig(
|
||||||
|
androidNotificationChannelId: 'es.freetimelab.pluriwave.audio',
|
||||||
|
androidNotificationChannelName: 'PluriWave Radio',
|
||||||
|
androidNotificationOngoing: true,
|
||||||
|
androidStopForegroundOnPause: true,
|
||||||
|
notificationColor: Color(0xFF6750A4),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
registrarHandler(handler);
|
||||||
|
|
||||||
runApp(const PluriWaveApp());
|
runApp(const PluriWaveApp());
|
||||||
}
|
}
|
||||||
|
|||||||
84
lib/pantallas/pantalla_ajustes.dart
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
|
||||||
|
/// Pantalla de ajustes — por ahora muestra info de la app.
|
||||||
|
/// En Fase 3 se añadirá Export/Import config y gestión PRO.
|
||||||
|
class PantallaAjustes extends StatelessWidget {
|
||||||
|
const PantallaAjustes({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Ajustes')),
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
// Info app
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.info_outline),
|
||||||
|
title: const Text('PluriWave'),
|
||||||
|
subtitle: const Text('v0.3.0 — Radio mundial'),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Favoritos
|
||||||
|
FutureBuilder<int>(
|
||||||
|
future: estado.favoritos.obtenerTodos().then((l) => l.length),
|
||||||
|
builder: (ctx, snap) => ListTile(
|
||||||
|
leading: const Icon(Icons.favorite_outline),
|
||||||
|
title: const Text('Favoritos guardados'),
|
||||||
|
trailing: Text(
|
||||||
|
snap.data?.toString() ?? '—',
|
||||||
|
style: theme.textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Filtro emisoras
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.verified_outlined),
|
||||||
|
title: const Text('Filtro de emisoras'),
|
||||||
|
subtitle: const Text('Solo emisoras verificadas como activas'),
|
||||||
|
trailing: const Icon(Icons.check_circle, color: Colors.green),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.music_off_outlined),
|
||||||
|
title: const Text('Audio en background'),
|
||||||
|
subtitle: const Text('Activo — continúa al apagar pantalla'),
|
||||||
|
trailing: const Icon(Icons.check_circle, color: Colors.green),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Próximamente
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||||
|
child: Text('PRÓXIMAMENTE', style: TextStyle(fontSize: 12, letterSpacing: 1.2)),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.upload_outlined),
|
||||||
|
title: const Text('Exportar configuración'),
|
||||||
|
subtitle: const Text('Favoritos, radios custom, presets EQ'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.download_outlined),
|
||||||
|
title: const Text('Importar configuración'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.add_circle_outline),
|
||||||
|
title: const Text('Añadir radio personalizada'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.equalizer_outlined),
|
||||||
|
title: const Text('Ecualizador'),
|
||||||
|
subtitle: const Text('5 bandas, presets por emisora'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
472
lib/pantallas/pantalla_reproductor.dart
Normal file
@@ -0,0 +1,472 @@
|
|||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shimmer/shimmer.dart';
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
import '../modelos/emisora.dart';
|
||||||
|
import '../servicios/servicio_audio.dart';
|
||||||
|
import '../servicios/servicio_timer.dart';
|
||||||
|
|
||||||
|
/// Pantalla completa del reproductor de radio.
|
||||||
|
///
|
||||||
|
/// Muestra: carátula/logo grande, nombre emisora, información (país, idioma,
|
||||||
|
/// codec/bitrate), controles play/pause, botón favorito, acceso al timer.
|
||||||
|
///
|
||||||
|
/// Se abre como ruta desde cualquier pantalla al pulsar sobre una emisora
|
||||||
|
/// o desde el MiniReproductor.
|
||||||
|
class PantallaReproductor extends StatefulWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
|
||||||
|
const PantallaReproductor({super.key, required this.emisora});
|
||||||
|
|
||||||
|
/// Navega a la pantalla del reproductor.
|
||||||
|
static Future<void> abrir(BuildContext context, Emisora emisora) {
|
||||||
|
return Navigator.push(
|
||||||
|
context,
|
||||||
|
PageRouteBuilder(
|
||||||
|
pageBuilder: (_, animation, __) => PantallaReproductor(emisora: emisora),
|
||||||
|
transitionsBuilder: (_, animation, __, child) => SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 1),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(CurvedAnimation(parent: animation, curve: Curves.easeOutCubic)),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
transitionDuration: const Duration(milliseconds: 350),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PantallaReproductor> createState() => _PantallaReproductorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PantallaReproductorState extends State<PantallaReproductor>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
late AnimationController _pulseController;
|
||||||
|
bool _esFavorito = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_pulseController = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
);
|
||||||
|
_checkFavorito();
|
||||||
|
_iniciarReproduccion();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _checkFavorito() async {
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
final fav = await estado.esFavorito(widget.emisora.uuid);
|
||||||
|
if (mounted) setState(() => _esFavorito = fav);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _iniciarReproduccion() async {
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
// Solo reproductor si no es ya la emisora activa
|
||||||
|
if (estado.emisoraActual?.uuid != widget.emisora.uuid) {
|
||||||
|
await estado.reproducir(widget.emisora);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_pulseController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final estado = context.watch<EstadoRadio>();
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: theme.colorScheme.surface,
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
elevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.keyboard_arrow_down_rounded, size: 32),
|
||||||
|
tooltip: 'Cerrar',
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
// Botón favorito
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_esFavorito ? Icons.favorite_rounded : Icons.favorite_outline_rounded,
|
||||||
|
color: _esFavorito ? theme.colorScheme.error : null,
|
||||||
|
),
|
||||||
|
tooltip: _esFavorito ? 'Quitar de favoritos' : 'Añadir a favoritos',
|
||||||
|
onPressed: () async {
|
||||||
|
final esFav = await estado.toggleFavorito(widget.emisora);
|
||||||
|
if (mounted) setState(() => _esFavorito = esFav);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const Spacer(flex: 1),
|
||||||
|
// Carátula / logo grande
|
||||||
|
_Artwork(
|
||||||
|
emisora: widget.emisora,
|
||||||
|
estadoStream: estado.estadoStream,
|
||||||
|
).animate().scale(begin: const Offset(0.8, 0.8), duration: 400.ms,
|
||||||
|
curve: Curves.easeOutBack),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
// Nombre de la emisora
|
||||||
|
Text(
|
||||||
|
widget.emisora.nombre,
|
||||||
|
style: theme.textTheme.headlineSmall?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
).animate().fadeIn(delay: 150.ms),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Info: país, idioma
|
||||||
|
_InfoChips(emisora: widget.emisora)
|
||||||
|
.animate()
|
||||||
|
.fadeIn(delay: 200.ms)
|
||||||
|
.slideY(begin: 0.2),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
// Codec / bitrate
|
||||||
|
if (widget.emisora.codec != null || widget.emisora.bitrate != null)
|
||||||
|
Text(
|
||||||
|
_codecInfo(widget.emisora),
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
).animate().fadeIn(delay: 250.ms),
|
||||||
|
const Spacer(flex: 2),
|
||||||
|
// Controles
|
||||||
|
_Controles(
|
||||||
|
estado: estado,
|
||||||
|
emisora: widget.emisora,
|
||||||
|
).animate().fadeIn(delay: 300.ms).slideY(begin: 0.3),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
// Timer
|
||||||
|
_TimerWidget(estado: estado)
|
||||||
|
.animate()
|
||||||
|
.fadeIn(delay: 400.ms),
|
||||||
|
const Spacer(flex: 1),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _codecInfo(Emisora e) {
|
||||||
|
final parts = <String>[];
|
||||||
|
if (e.codec != null) parts.add(e.codec!.toUpperCase());
|
||||||
|
if (e.bitrate != null && e.bitrate! > 0) parts.add('${e.bitrate} kbps');
|
||||||
|
return parts.join(' · ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Artwork ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _Artwork extends StatelessWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
final Stream<EstadoReproduccion> estadoStream;
|
||||||
|
|
||||||
|
const _Artwork({required this.emisora, required this.estadoStream});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final size = MediaQuery.of(context).size.width * 0.65;
|
||||||
|
|
||||||
|
return StreamBuilder<EstadoReproduccion>(
|
||||||
|
stream: estadoStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final reproduciendo = snapshot.data == EstadoReproduccion.reproduciendo;
|
||||||
|
final cargando = snapshot.data == EstadoReproduccion.cargando;
|
||||||
|
|
||||||
|
return AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
boxShadow: reproduciendo
|
||||||
|
? [
|
||||||
|
BoxShadow(
|
||||||
|
color: theme.colorScheme.primary.withValues(alpha: 0.4),
|
||||||
|
blurRadius: 30,
|
||||||
|
spreadRadius: 5,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.2),
|
||||||
|
blurRadius: 12,
|
||||||
|
spreadRadius: 2,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
child: Stack(
|
||||||
|
fit: StackFit.expand,
|
||||||
|
children: [
|
||||||
|
// Logo / imagen
|
||||||
|
if (emisora.favicon != null && emisora.favicon!.isNotEmpty)
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: emisora.favicon!,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (_, __) => _shimmer(theme),
|
||||||
|
errorWidget: (_, __, ___) => _iconoFallback(theme),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_iconoFallback(theme),
|
||||||
|
// Overlay de carga
|
||||||
|
if (cargando)
|
||||||
|
Container(
|
||||||
|
color: Colors.black45,
|
||||||
|
child: const Center(
|
||||||
|
child: CircularProgressIndicator(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _shimmer(ThemeData theme) => Shimmer.fromColors(
|
||||||
|
baseColor: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
highlightColor: theme.colorScheme.surface,
|
||||||
|
child: Container(color: theme.colorScheme.surfaceContainerHighest),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _iconoFallback(ThemeData theme) => Container(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
child: Icon(
|
||||||
|
Icons.radio_rounded,
|
||||||
|
size: 80,
|
||||||
|
color: theme.colorScheme.onPrimaryContainer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Info chips ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _InfoChips extends StatelessWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
const _InfoChips({required this.emisora});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final items = <String>[];
|
||||||
|
if (emisora.pais != null) items.add(emisora.pais!);
|
||||||
|
if (emisora.idioma != null) items.add(emisora.idioma!);
|
||||||
|
if (items.isEmpty) return const SizedBox.shrink();
|
||||||
|
|
||||||
|
return Wrap(
|
||||||
|
spacing: 6,
|
||||||
|
children: items
|
||||||
|
.map((label) => Chip(
|
||||||
|
label: Text(label),
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
backgroundColor: theme.colorScheme.secondaryContainer,
|
||||||
|
labelStyle: TextStyle(
|
||||||
|
color: theme.colorScheme.onSecondaryContainer,
|
||||||
|
fontSize: 12),
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Controles ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _Controles extends StatelessWidget {
|
||||||
|
final EstadoRadio estado;
|
||||||
|
final Emisora emisora;
|
||||||
|
|
||||||
|
const _Controles({required this.estado, required this.emisora});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return StreamBuilder<EstadoReproduccion>(
|
||||||
|
stream: estado.estadoStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final s = snapshot.data ?? EstadoReproduccion.detenido;
|
||||||
|
final reproduciendo = s == EstadoReproduccion.reproduciendo;
|
||||||
|
final cargando = s == EstadoReproduccion.cargando;
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
// Botón detener
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.stop_rounded),
|
||||||
|
iconSize: 36,
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
tooltip: 'Detener',
|
||||||
|
onPressed: cargando ? null : () => estado.audio.detener(),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
// Botón play/pause principal
|
||||||
|
AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
width: 72,
|
||||||
|
height: 72,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: theme.colorScheme.primary.withValues(alpha: 0.35),
|
||||||
|
blurRadius: reproduciendo ? 16 : 6,
|
||||||
|
spreadRadius: reproduciendo ? 4 : 0,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
child: InkWell(
|
||||||
|
customBorder: const CircleBorder(),
|
||||||
|
onTap: cargando
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
if (reproduciendo || s == EstadoReproduccion.pausado) {
|
||||||
|
estado.togglePlay();
|
||||||
|
} else {
|
||||||
|
estado.reproducir(emisora);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: cargando
|
||||||
|
? const SizedBox(
|
||||||
|
width: 28,
|
||||||
|
height: 28,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2.5,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
reproduciendo
|
||||||
|
? Icons.pause_rounded
|
||||||
|
: Icons.play_arrow_rounded,
|
||||||
|
size: 40,
|
||||||
|
color: theme.colorScheme.onPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
// Indicador en vivo
|
||||||
|
Icon(
|
||||||
|
Icons.fiber_manual_record_rounded,
|
||||||
|
size: 36,
|
||||||
|
color: reproduciendo
|
||||||
|
? theme.colorScheme.error
|
||||||
|
: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Timer widget ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _TimerWidget extends StatelessWidget {
|
||||||
|
final EstadoRadio estado;
|
||||||
|
const _TimerWidget({required this.estado});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
if (!estado.timer.activo) {
|
||||||
|
return TextButton.icon(
|
||||||
|
icon: const Icon(Icons.bedtime_outlined, size: 18),
|
||||||
|
label: const Text('Timer de sueño'),
|
||||||
|
onPressed: () => _mostrarTimerDialog(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return StreamBuilder<Duration>(
|
||||||
|
stream: estado.timer.tiempoRestanteStream,
|
||||||
|
builder: (context, snap) {
|
||||||
|
final t = snap.data ?? Duration.zero;
|
||||||
|
final m = t.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||||
|
final s = t.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||||
|
final label = t.inHours > 0
|
||||||
|
? '${t.inHours}h ${m}m'
|
||||||
|
: '${m}m ${s}s';
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.bedtime_rounded, size: 16, color: theme.colorScheme.primary),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(label, style: theme.textTheme.bodyMedium),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => estado.cancelarTimer(),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
|
),
|
||||||
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _mostrarTimerDialog(BuildContext context) {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Timer de sueño', style: Theme.of(ctx).textTheme.titleLarge),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: opcionesTimer
|
||||||
|
.map((min) => ActionChip(
|
||||||
|
label: Text('$min min'),
|
||||||
|
onPressed: () {
|
||||||
|
estado.iniciarTimer(min);
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,115 +5,89 @@ import '../modelos/emisora.dart';
|
|||||||
/// Estado de reproducción expuesto al UI.
|
/// Estado de reproducción expuesto al UI.
|
||||||
enum EstadoReproduccion { detenido, cargando, reproduciendo, pausado, error }
|
enum EstadoReproduccion { detenido, cargando, reproduciendo, pausado, error }
|
||||||
|
|
||||||
/// Wrapper sobre just_audio + audio_service para reproducción de radio en streaming.
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
// Handler global — inicializado en main.dart con AudioService.init
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
PluriWaveAudioHandler? _handlerGlobal;
|
||||||
|
|
||||||
|
/// Registra el handler. Llamar desde main.dart tras AudioService.init.
|
||||||
|
void registrarHandler(PluriWaveAudioHandler handler) {
|
||||||
|
_handlerGlobal = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wrapper de alto nivel para el UI.
|
||||||
///
|
///
|
||||||
/// ### Uso
|
/// Delega TODA la reproducción al [PluriWaveAudioHandler] para garantizar
|
||||||
/// ```dart
|
/// que el audio siga vivo en background con notificación foreground.
|
||||||
/// final servicio = ServicioAudio();
|
|
||||||
/// await servicio.inicializar();
|
|
||||||
/// await servicio.reproducir(emisora);
|
|
||||||
/// await servicio.pausar();
|
|
||||||
/// await servicio.detener();
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ### Background audio
|
|
||||||
/// Para habilitar reproducción en background, el handler [PluriWaveAudioHandler]
|
|
||||||
/// debe registrarse en main.dart con [AudioService.init]. Si no está registrado,
|
|
||||||
/// just_audio seguirá funcionando en foreground.
|
|
||||||
class ServicioAudio {
|
class ServicioAudio {
|
||||||
final AudioPlayer _player = AudioPlayer();
|
PluriWaveAudioHandler get _handler {
|
||||||
Emisora? _emisoraActual;
|
assert(_handlerGlobal != null,
|
||||||
|
'ServicioAudio: handler no registrado. '
|
||||||
|
'Llama registrarHandler() en main.dart tras AudioService.init.');
|
||||||
|
return _handlerGlobal!;
|
||||||
|
}
|
||||||
|
|
||||||
EstadoReproduccion _estado = EstadoReproduccion.detenido;
|
Emisora? get emisoraActual => _handler.emisoraActual;
|
||||||
EstadoReproduccion get estado => _estado;
|
|
||||||
Emisora? get emisoraActual => _emisoraActual;
|
|
||||||
|
|
||||||
/// Stream de cambios de estado para el UI.
|
Stream<EstadoReproduccion> get estadoStream =>
|
||||||
Stream<EstadoReproduccion> get estadoStream => _player.playerStateStream.map(
|
_handler.playbackState.map((s) {
|
||||||
(s) {
|
if (s.processingState == AudioProcessingState.loading ||
|
||||||
if (s.processingState == ProcessingState.loading ||
|
s.processingState == AudioProcessingState.buffering) {
|
||||||
s.processingState == ProcessingState.buffering) {
|
return EstadoReproduccion.cargando;
|
||||||
return EstadoReproduccion.cargando;
|
}
|
||||||
}
|
if (s.playing) return EstadoReproduccion.reproduciendo;
|
||||||
if (s.playing) return EstadoReproduccion.reproduciendo;
|
if (s.processingState == AudioProcessingState.idle) {
|
||||||
if (s.processingState == ProcessingState.idle) return EstadoReproduccion.detenido;
|
return EstadoReproduccion.detenido;
|
||||||
return EstadoReproduccion.pausado;
|
}
|
||||||
},
|
return EstadoReproduccion.pausado;
|
||||||
);
|
});
|
||||||
|
|
||||||
/// Inicia la reproducción de la [emisora] indicada.
|
|
||||||
Future<void> reproducir(Emisora emisora) async {
|
Future<void> reproducir(Emisora emisora) async {
|
||||||
try {
|
final item = MediaItem(
|
||||||
_estado = EstadoReproduccion.cargando;
|
id: emisora.url,
|
||||||
|
title: emisora.nombre,
|
||||||
// Si es la misma emisora, reanudar sin recargar
|
artist: emisora.pais ?? '',
|
||||||
if (_emisoraActual?.uuid == emisora.uuid && _player.audioSource != null) {
|
album: 'PluriWave',
|
||||||
await _player.play();
|
artUri: emisora.favicon != null && emisora.favicon!.isNotEmpty
|
||||||
_estado = EstadoReproduccion.reproduciendo;
|
? Uri.tryParse(emisora.favicon!)
|
||||||
return;
|
: null,
|
||||||
}
|
extras: {'uuid': emisora.uuid},
|
||||||
|
);
|
||||||
_emisoraActual = emisora;
|
await _handler.playMediaItem(item);
|
||||||
await _player.stop();
|
|
||||||
await _player.setUrl(emisora.url);
|
|
||||||
await _player.play();
|
|
||||||
_estado = EstadoReproduccion.reproduciendo;
|
|
||||||
} on PlayerException catch (_) {
|
|
||||||
_estado = EstadoReproduccion.error;
|
|
||||||
rethrow;
|
|
||||||
} catch (e) {
|
|
||||||
_estado = EstadoReproduccion.error;
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pausa la reproducción actual.
|
Future<void> pausar() => _handler.pause();
|
||||||
Future<void> pausar() async {
|
Future<void> reanudar() => _handler.play();
|
||||||
await _player.pause();
|
|
||||||
_estado = EstadoReproduccion.pausado;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reanuda si estaba pausado.
|
|
||||||
Future<void> reanudar() async {
|
|
||||||
if (_player.audioSource != null) {
|
|
||||||
await _player.play();
|
|
||||||
_estado = EstadoReproduccion.reproduciendo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Alterna entre pausa y reproducción.
|
|
||||||
Future<void> togglePlay() async {
|
Future<void> togglePlay() async {
|
||||||
if (_player.playing) {
|
if (_handler.playbackState.value.playing) {
|
||||||
await pausar();
|
await pausar();
|
||||||
} else {
|
} else {
|
||||||
await reanudar();
|
await reanudar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Detiene la reproducción y libera la fuente.
|
Future<void> detener() => _handler.stop();
|
||||||
Future<void> detener() async {
|
|
||||||
await _player.stop();
|
|
||||||
_emisoraActual = null;
|
|
||||||
_estado = EstadoReproduccion.detenido;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ajusta el volumen (0.0 - 1.0).
|
Future<void> setVolumen(double vol) => _handler.setVolume(vol.clamp(0.0, 1.0));
|
||||||
Future<void> setVolumen(double volumen) async {
|
|
||||||
await _player.setVolume(volumen.clamp(0.0, 1.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
double get volumen => _player.volume;
|
double get volumen => _handler.volumen;
|
||||||
bool get estaSonando => _player.playing;
|
bool get estaSonando => _handler.playbackState.value.playing;
|
||||||
|
|
||||||
/// Libera recursos. Llamar al destruir la pantalla raíz.
|
/// No-op: el handler se limpia en main.dart al cerrar la app.
|
||||||
Future<void> dispose() async {
|
Future<void> dispose() async {}
|
||||||
await _player.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handler de audio_service para reproducción en background con notificación.
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
// AudioHandler — núcleo del audio en background
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// Handler de audio_service.
|
||||||
///
|
///
|
||||||
/// Registrar en main.dart:
|
/// Gestiona la reproducción con `just_audio` y mantiene la notificación
|
||||||
|
/// foreground activa mientras hay audio reproduciéndose.
|
||||||
|
///
|
||||||
|
/// ### Inicialización en main.dart
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// final handler = await AudioService.init(
|
/// final handler = await AudioService.init(
|
||||||
/// builder: () => PluriWaveAudioHandler(),
|
/// builder: () => PluriWaveAudioHandler(),
|
||||||
@@ -122,40 +96,72 @@ class ServicioAudio {
|
|||||||
/// androidNotificationChannelName: 'PluriWave Radio',
|
/// androidNotificationChannelName: 'PluriWave Radio',
|
||||||
/// androidNotificationOngoing: true,
|
/// androidNotificationOngoing: true,
|
||||||
/// androidStopForegroundOnPause: true,
|
/// androidStopForegroundOnPause: true,
|
||||||
|
/// androidNotificationIcon: 'drawable/ic_stat_radio',
|
||||||
/// ),
|
/// ),
|
||||||
/// );
|
/// );
|
||||||
|
/// registrarHandler(handler);
|
||||||
/// ```
|
/// ```
|
||||||
class PluriWaveAudioHandler extends BaseAudioHandler with SeekHandler {
|
class PluriWaveAudioHandler extends BaseAudioHandler with SeekHandler {
|
||||||
final AudioPlayer _player = AudioPlayer();
|
final AudioPlayer _player = AudioPlayer();
|
||||||
|
Emisora? emisoraActual;
|
||||||
|
double _volumen = 1.0;
|
||||||
|
double get volumen => _volumen;
|
||||||
|
|
||||||
PluriWaveAudioHandler() {
|
PluriWaveAudioHandler() {
|
||||||
|
_setupStreams();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setupStreams() {
|
||||||
|
// Propagar estado del player → playbackState (lo que ve la notificación)
|
||||||
_player.playerStateStream.listen((state) {
|
_player.playerStateStream.listen((state) {
|
||||||
final playing = state.playing;
|
final playing = state.playing;
|
||||||
final proc = state.processingState;
|
final proc = state.processingState;
|
||||||
|
|
||||||
playbackState.add(playbackState.value.copyWith(
|
playbackState.add(playbackState.value.copyWith(
|
||||||
controls: [
|
controls: [
|
||||||
if (playing) MediaControl.pause else MediaControl.play,
|
if (playing) MediaControl.pause else MediaControl.play,
|
||||||
MediaControl.stop,
|
MediaControl.stop,
|
||||||
],
|
],
|
||||||
systemActions: const {MediaAction.seek},
|
systemActions: const {MediaAction.seek, MediaAction.stop},
|
||||||
androidCompactActionIndices: const [0],
|
androidCompactActionIndices: const [0],
|
||||||
processingState: {
|
processingState: _mapProcState(proc),
|
||||||
ProcessingState.idle: AudioProcessingState.idle,
|
|
||||||
ProcessingState.loading: AudioProcessingState.loading,
|
|
||||||
ProcessingState.buffering: AudioProcessingState.buffering,
|
|
||||||
ProcessingState.ready: AudioProcessingState.ready,
|
|
||||||
ProcessingState.completed: AudioProcessingState.completed,
|
|
||||||
}[proc]!,
|
|
||||||
playing: playing,
|
playing: playing,
|
||||||
|
bufferedPosition: _player.bufferedPosition,
|
||||||
|
speed: _player.speed,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Actualizar bufferedPosition
|
||||||
|
_player.bufferedPositionStream.listen((pos) {
|
||||||
|
playbackState.add(playbackState.value.copyWith(bufferedPosition: pos));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioProcessingState _mapProcState(ProcessingState state) {
|
||||||
|
return switch (state) {
|
||||||
|
ProcessingState.idle => AudioProcessingState.idle,
|
||||||
|
ProcessingState.loading => AudioProcessingState.loading,
|
||||||
|
ProcessingState.buffering => AudioProcessingState.buffering,
|
||||||
|
ProcessingState.ready => AudioProcessingState.ready,
|
||||||
|
ProcessingState.completed => AudioProcessingState.completed,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> playMediaItem(MediaItem item) async {
|
Future<void> playMediaItem(MediaItem item) async {
|
||||||
mediaItem.add(item);
|
mediaItem.add(item);
|
||||||
await _player.setUrl(item.id);
|
try {
|
||||||
await _player.play();
|
await _player.stop();
|
||||||
|
await _player.setUrl(item.id);
|
||||||
|
await _player.play();
|
||||||
|
} on PlayerException catch (e) {
|
||||||
|
playbackState.add(playbackState.value.copyWith(
|
||||||
|
processingState: AudioProcessingState.error,
|
||||||
|
errorMessage: e.message ?? 'Error de reproducción',
|
||||||
|
errorCode: e.code,
|
||||||
|
));
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -167,9 +173,22 @@ class PluriWaveAudioHandler extends BaseAudioHandler with SeekHandler {
|
|||||||
@override
|
@override
|
||||||
Future<void> stop() async {
|
Future<void> stop() async {
|
||||||
await _player.stop();
|
await _player.stop();
|
||||||
|
emisoraActual = null;
|
||||||
|
mediaItem.add(null);
|
||||||
await super.stop();
|
await super.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> seek(Duration position) => _player.seek(position);
|
Future<void> seek(Duration position) => _player.seek(position);
|
||||||
|
|
||||||
|
Future<void> setVolume(double vol) async {
|
||||||
|
_volumen = vol.clamp(0.0, 1.0);
|
||||||
|
await _player.setVolume(_volumen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onTaskRemoved() async {
|
||||||
|
await stop();
|
||||||
|
await _player.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,11 @@ class ServicioRadio {
|
|||||||
|
|
||||||
Future<List<Emisora>> _get(String path, Map<String, String> params) async {
|
Future<List<Emisora>> _get(String path, Map<String, String> params) async {
|
||||||
final servidor = await _servidor();
|
final servidor = await _servidor();
|
||||||
final uri = _uri(servidor, path, params);
|
// lastcheckok=1 filtra emisoras que la API verificó como funcionales
|
||||||
|
final uri = _uri(servidor, path, {
|
||||||
|
'lastcheckok': '1',
|
||||||
|
...params,
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
final resp = await http.get(uri, headers: {
|
final resp = await http.get(uri, headers: {
|
||||||
'User-Agent': 'PluriWave/0.1.0 (es.freetimelab.pluriwave)',
|
'User-Agent': 'PluriWave/0.1.0 (es.freetimelab.pluriwave)',
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../estado/estado_radio.dart';
|
import '../estado/estado_radio.dart';
|
||||||
|
import '../pantallas/pantalla_reproductor.dart';
|
||||||
import '../servicios/servicio_audio.dart';
|
import '../servicios/servicio_audio.dart';
|
||||||
|
|
||||||
/// Barra inferior persistente con controles básicos de reproducción.
|
/// Barra inferior persistente con controles básicos de reproducción.
|
||||||
/// Se muestra siempre que haya una emisora cargada.
|
/// Toca la barra para abrir PantallaReproductor completa.
|
||||||
class MiniReproductor extends StatelessWidget {
|
class MiniReproductor extends StatelessWidget {
|
||||||
const MiniReproductor({super.key});
|
const MiniReproductor({super.key});
|
||||||
|
|
||||||
@@ -17,80 +18,94 @@ class MiniReproductor extends StatelessWidget {
|
|||||||
|
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return Container(
|
return GestureDetector(
|
||||||
decoration: BoxDecoration(
|
onTap: () => PantallaReproductor.abrir(context, emisora),
|
||||||
color: theme.colorScheme.surfaceContainer,
|
child: Container(
|
||||||
border: Border(top: BorderSide(color: theme.colorScheme.outlineVariant, width: 0.5)),
|
decoration: BoxDecoration(
|
||||||
),
|
color: theme.colorScheme.surfaceContainer,
|
||||||
child: SafeArea(
|
border: Border(
|
||||||
top: false,
|
top: BorderSide(
|
||||||
child: Padding(
|
color: theme.colorScheme.outlineVariant, width: 0.5)),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
),
|
||||||
child: Row(
|
child: SafeArea(
|
||||||
children: [
|
top: false,
|
||||||
// Logo emisora
|
child: Padding(
|
||||||
ClipRRect(
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
borderRadius: BorderRadius.circular(6),
|
child: Row(
|
||||||
child: Container(
|
children: [
|
||||||
width: 40,
|
// Logo
|
||||||
height: 40,
|
ClipRRect(
|
||||||
color: theme.colorScheme.primaryContainer,
|
borderRadius: BorderRadius.circular(6),
|
||||||
child: const Icon(Icons.radio, size: 22),
|
child: Container(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
child: Icon(Icons.radio,
|
||||||
|
size: 22,
|
||||||
|
color: theme.colorScheme.onPrimaryContainer),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 12),
|
||||||
const SizedBox(width: 12),
|
// Nombre y estado
|
||||||
// Nombre y estado
|
Expanded(
|
||||||
Expanded(
|
child: Column(
|
||||||
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
emisora.nombre,
|
||||||
emisora.nombre,
|
style: theme.textTheme.bodyMedium
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w600),
|
?.copyWith(fontWeight: FontWeight.w600),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
|
||||||
StreamBuilder<EstadoReproduccion>(
|
|
||||||
stream: estado.estadoStream,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final s = snapshot.data ?? EstadoReproduccion.detenido;
|
|
||||||
return Text(
|
|
||||||
_labelEstado(s),
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Botón play/pause
|
|
||||||
StreamBuilder<EstadoReproduccion>(
|
|
||||||
stream: estado.estadoStream,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final s = snapshot.data ?? EstadoReproduccion.detenido;
|
|
||||||
if (s == EstadoReproduccion.cargando) {
|
|
||||||
return const SizedBox(
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(10),
|
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
|
||||||
),
|
),
|
||||||
|
StreamBuilder<EstadoReproduccion>(
|
||||||
|
stream: estado.estadoStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final s = snapshot.data ??
|
||||||
|
EstadoReproduccion.detenido;
|
||||||
|
return Text(
|
||||||
|
_labelEstado(s),
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Botón play/pause
|
||||||
|
StreamBuilder<EstadoReproduccion>(
|
||||||
|
stream: estado.estadoStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final s =
|
||||||
|
snapshot.data ?? EstadoReproduccion.detenido;
|
||||||
|
if (s == EstadoReproduccion.cargando) {
|
||||||
|
return const SizedBox(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(10),
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
s == EstadoReproduccion.reproduciendo
|
||||||
|
? Icons.pause_rounded
|
||||||
|
: Icons.play_arrow_rounded,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
// Evitar que el tap en el botón abra el reproductor
|
||||||
|
estado.togglePlay();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
return IconButton(
|
),
|
||||||
icon: Icon(s == EstadoReproduccion.reproduciendo
|
],
|
||||||
? Icons.pause_rounded
|
),
|
||||||
: Icons.play_arrow_rounded),
|
|
||||||
onPressed: estado.togglePlay,
|
|
||||||
tooltip: s == EstadoReproduccion.reproduciendo ? 'Pausar' : 'Reproducir',
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -98,17 +113,12 @@ class MiniReproductor extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _labelEstado(EstadoReproduccion estado) {
|
String _labelEstado(EstadoReproduccion estado) {
|
||||||
switch (estado) {
|
return switch (estado) {
|
||||||
case EstadoReproduccion.cargando:
|
EstadoReproduccion.cargando => 'Conectando...',
|
||||||
return 'Conectando...';
|
EstadoReproduccion.reproduciendo => 'En directo ●',
|
||||||
case EstadoReproduccion.reproduciendo:
|
EstadoReproduccion.pausado => 'Pausado',
|
||||||
return 'En directo ●';
|
EstadoReproduccion.error => 'Error de conexión',
|
||||||
case EstadoReproduccion.pausado:
|
EstadoReproduccion.detenido => 'Detenido',
|
||||||
return 'Pausado';
|
};
|
||||||
case EstadoReproduccion.error:
|
|
||||||
return 'Error de conexión';
|
|
||||||
case EstadoReproduccion.detenido:
|
|
||||||
return 'Detenido';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||