Enabled image file scan (#151)
This commit is contained in:
parent
ec36fcd105
commit
a750a52e2e
1 changed files with 20 additions and 15 deletions
|
@ -23,7 +23,7 @@ import 'local_music_fetcher.dart';
|
|||
import 'music_data_source_contract.dart';
|
||||
import 'settings_data_source.dart';
|
||||
|
||||
const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png'];
|
||||
const IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png'];
|
||||
|
||||
class LocalMusicFetcherImpl implements LocalMusicFetcher {
|
||||
LocalMusicFetcherImpl(
|
||||
|
@ -140,22 +140,27 @@ class LocalMusicFetcherImpl implements LocalMusicFetcher {
|
|||
albumIdMap[albumString] = albumId;
|
||||
newAlbumId = max(newAlbumId, albumId + 1);
|
||||
|
||||
final Uint8List? albumArt = songData.picture?.data;
|
||||
Uint8List? albumArt = songData.picture?.data;
|
||||
|
||||
// fallback to get albumArt
|
||||
// TODO: enable when everything else works as expected
|
||||
// if (albumArt == null) {
|
||||
// // get directory of song and look for image files
|
||||
// final images = await songFile.parent
|
||||
// .list(recursive: false, followLinks: false)
|
||||
// .where((item) =>
|
||||
// FileSystemEntity.isFileSync(item.path) &&
|
||||
// IMAGE_EXTENSIONS.contains(
|
||||
// p.extension(item.path).toLowerCase().substring(1)))
|
||||
// .asyncMap((item) => File(item.path))
|
||||
// .toList();
|
||||
// if (images.isNotEmpty) albumArt = images.first.readAsBytesSync();
|
||||
// }
|
||||
if (albumArt == null) {
|
||||
// get directory of song and look for image files
|
||||
final images = await songFile.parent
|
||||
.list(recursive: false, followLinks: false)
|
||||
.where((item) =>
|
||||
FileSystemEntity.isFileSync(item.path) &&
|
||||
IMAGE_EXTENSIONS.contains(p.extension(item.path).toLowerCase()))
|
||||
.asyncMap((item) => File(item.path))
|
||||
.toList();
|
||||
for (final image in images) {
|
||||
try {
|
||||
albumArt = image.readAsBytesSync();
|
||||
break;
|
||||
} catch (e) {
|
||||
_log.e('Could not read image file: ${image.path}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (albumArt != null) {
|
||||
albumArtMap[albumId] = await cacheAlbumArt(albumArt, albumId);
|
||||
|
|
Loading…
Add table
Reference in a new issue