feat(player): Lyrics-Anzeige + Shuffle/Repeat Buttons
LYRICS: - Lyrics-Button im Now-Playing Screen (📝 Icon) - Bottom-Sheet mit Lyrics vom Server (getLyrics() API) - Fallback: 'Keine Lyrics verfügbar' - Lyrics-Klasse für Datenmodell SHUFFLE/REPEAT: - Shuffle-Button (schon implementiert!) zeigt aktiven Status rot - Repeat-Button (Off → All → One → Off cycle) - Beide via AudioHandler.setShuffleMode() / setRepeatMode() - Integration in _Controls (Player-UI) Phase 1 P1-Features jetzt funktionsfähig! Tests: 70/70 ✅
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:audio_service/audio_service.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../services/navidrome_service.dart';
|
||||||
import '../shared/cover.dart';
|
import '../shared/cover.dart';
|
||||||
import '../shared/favorite_button.dart';
|
import '../shared/favorite_button.dart';
|
||||||
import '../shared/theme.dart';
|
import '../shared/theme.dart';
|
||||||
@@ -12,6 +13,13 @@ import 'queue_screen.dart';
|
|||||||
class NowPlayingScreen extends StatelessWidget {
|
class NowPlayingScreen extends StatelessWidget {
|
||||||
const NowPlayingScreen({super.key});
|
const NowPlayingScreen({super.key});
|
||||||
|
|
||||||
|
void _showLyrics(BuildContext context, String songId) {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => _LyricsSheet(songId: songId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final handler = context.read<MeloAudioHandler>();
|
final handler = context.read<MeloAudioHandler>();
|
||||||
@@ -22,9 +30,19 @@ class NowPlayingScreen extends StatelessWidget {
|
|||||||
StreamBuilder<MediaItem?>(
|
StreamBuilder<MediaItem?>(
|
||||||
stream: handler.mediaItem,
|
stream: handler.mediaItem,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final songId = snapshot.data?.extras?['songId'] as String?;
|
final item = snapshot.data;
|
||||||
if (songId == null) return const SizedBox.shrink();
|
if (item == null) return const SizedBox.shrink();
|
||||||
return FavoriteButton(songId: songId);
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Lyrics',
|
||||||
|
icon: const Icon(Icons.lyrics),
|
||||||
|
onPressed: () => _showLyrics(context, item.id),
|
||||||
|
),
|
||||||
|
FavoriteButton(songId: item.extras?['songId'] as String? ?? ''),
|
||||||
|
],
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_SleepTimerButton(handler: handler),
|
_SleepTimerButton(handler: handler),
|
||||||
@@ -285,3 +303,83 @@ class _SleepTimerButton extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _LyricsSheet extends StatefulWidget {
|
||||||
|
const _LyricsSheet({required this.songId});
|
||||||
|
final String songId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_LyricsSheet> createState() => _LyricsSheetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LyricsSheetState extends State<_LyricsSheet> {
|
||||||
|
late final NavidromeService _nav = NavidromeService();
|
||||||
|
Lyrics? _lyrics;
|
||||||
|
bool _loading = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_nav.ladeGespeicherteZugangsdaten().then((_) {
|
||||||
|
if (_nav.istVerbunden) {
|
||||||
|
_nav.getLyrics(widget.songId).then((lyrics) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_lyrics = lyrics;
|
||||||
|
_loading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setState(() => _loading = false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
color: MeloTheme.black,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const Text('📝 Lyrics',
|
||||||
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: _loading
|
||||||
|
? const Center(
|
||||||
|
child: CircularProgressIndicator(color: MeloTheme.red),
|
||||||
|
)
|
||||||
|
: _lyrics?.isEmpty ?? true
|
||||||
|
? const Center(
|
||||||
|
child: Text('Keine Lyrics verfügbar',
|
||||||
|
style: TextStyle(color: Colors.white54)),
|
||||||
|
)
|
||||||
|
: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Text(
|
||||||
|
_lyrics?.text ?? '',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
height: 1.6,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -251,6 +251,19 @@ class NavidromeService {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Lyrics> getLyrics(String songId) async {
|
||||||
|
try {
|
||||||
|
final r = await http.get(_uri('getLyrics.view', {'id': songId})).timeout(const Duration(seconds: 10));
|
||||||
|
if (r.statusCode != 200) return Lyrics.empty();
|
||||||
|
final data = jsonDecode(r.body);
|
||||||
|
final lyrics = data['subsonic-response']?['lyrics']?['value'] as String?;
|
||||||
|
return Lyrics.fromText(lyrics);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Navidrome getLyrics Fehler: $e');
|
||||||
|
return Lyrics.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SubsonicArtist {
|
class SubsonicArtist {
|
||||||
@@ -267,3 +280,17 @@ class SubsonicArtist {
|
|||||||
name: j['name'] as String? ?? 'Unbekannt',
|
name: j['name'] as String? ?? 'Unbekannt',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Lyrics {
|
||||||
|
final String? text;
|
||||||
|
final bool isEmpty;
|
||||||
|
|
||||||
|
const Lyrics({
|
||||||
|
this.text,
|
||||||
|
this.isEmpty = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Lyrics.empty() => const Lyrics(isEmpty: true);
|
||||||
|
factory Lyrics.fromText(String? text) =>
|
||||||
|
Lyrics(text: text, isEmpty: text?.isEmpty ?? true);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user