import 'package:audio_service/audio_service.dart'; import '../player/audio_handler.dart'; import 'database.dart'; /// [cover] überschreibt das Coverbild des Songs — damit auf Sperrbildschirm /// und in der Benachrichtigung dasselbe Bild erscheint wie in der App /// (Einstellung "Gleiche Kategorie = gleiches Coverbild"). MediaItem songToMediaItem(Song s, {String? cover}) { final art = cover ?? s.coverPath; return MediaItem( id: Uri.file(s.path).toString(), title: s.title, artist: s.artist, album: s.album, duration: s.durationMs != null ? Duration(milliseconds: s.durationMs!) : null, artUri: art != null ? Uri.file(art) : null, extras: {'songId': s.id, 'gainDb': s.gainDb}, ); } /// Spielt [songs] ab [startIndex] ab. [coverOf] liefert je Song das /// anzuzeigende Cover (siehe [songToMediaItem]). Future playSongs( MeloAudioHandler handler, List songs, int startIndex, { String? Function(Song)? coverOf, }) { return handler.loadPlaylist( [for (final s in songs) songToMediaItem(s, cover: coverOf?.call(s))], startIndex: startIndex, ); }