mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 07:34:13 +01:00
A tester reported that offline most thumbnails in playlists, albums, folders, genres and artists disappear, while song rows keep theirs. Song rows show the artwork inside the song file first. The other places draw the cover's web address whenever a download has one, and a web cover is only kept in a cache that is capped at 1000 images and 150 MB and shared with every Home and Search image, so most of a large library is not in it. The album page asks for a larger version at another address, which is why a cover seen there did not help its tile. Those places now fall back to the artwork inside a song file on the device when the cover fails to load: Mornye album, artist and genre tiles, Material artist and genre rows, folders and their song rows, playlist rows and tiles, Library search results and the Up Next rows. Online nothing changes, since the file is read only after a failure. A playlist row or tile looks its file up in the database at that moment. Songs on network storage are left out. Cover requests also give up connecting after ten seconds, so a network without internet reaches the fallback instead of waiting for the system's timeout.
66 lines
2.0 KiB
Dart
66 lines
2.0 KiB
Dart
import 'package:audio_service/audio_service.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:mornye/services/cover_store.dart';
|
|
import 'package:mornye/widgets/cached_cover_image.dart';
|
|
import 'package:mornye/widgets/local_library_artwork_builder.dart';
|
|
import 'package:mornye/widgets/player_artwork.dart';
|
|
|
|
/// Queue entries may not have artwork yet, as for files a phone sent through
|
|
/// Link. Recover only visible rows through the shared bounded cover cache.
|
|
class PlayerQueueArtwork extends StatelessWidget {
|
|
const PlayerQueueArtwork({
|
|
super.key,
|
|
required this.item,
|
|
required this.colorScheme,
|
|
required this.cacheWidth,
|
|
this.iconSize = 22,
|
|
});
|
|
|
|
final MediaItem item;
|
|
final ColorScheme colorScheme;
|
|
final int cacheWidth;
|
|
final double iconSize;
|
|
|
|
String? get _localSource {
|
|
var source = item.extras?['source']?.toString() ?? item.id;
|
|
if (source.startsWith('file://')) {
|
|
try {
|
|
source = Uri.parse(source).toFilePath();
|
|
} on FormatException {
|
|
return null;
|
|
} on UnsupportedError {
|
|
return null;
|
|
}
|
|
}
|
|
return p.isAbsolute(source) || source.startsWith('content://')
|
|
? source
|
|
: null;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// A network cover not stored yet shows once a visible row fetched it.
|
|
final artwork =
|
|
item.artUri?.toString() ?? item.extras?['artworkRef']?.toString();
|
|
final source = _localSource;
|
|
Widget image(String? uri, {String? songFile}) => PlayerArtwork(
|
|
artUri: uri,
|
|
colorScheme: colorScheme,
|
|
cacheWidth: cacheWidth,
|
|
iconSize: iconSize,
|
|
songFile: songFile,
|
|
);
|
|
if (source == null ||
|
|
isHttpCoverUrl(artwork) ||
|
|
CoverStore.fetches(artwork)) {
|
|
return image(artwork, songFile: isHttpCoverUrl(artwork) ? source : null);
|
|
}
|
|
return LocalLibraryArtworkBuilder(
|
|
coverPath: artwork,
|
|
filePath: source,
|
|
builder: (_, cover) => image(cover),
|
|
);
|
|
}
|
|
}
|