fixed albumart on Android 10
This commit is contained in:
parent
3acfd0e978
commit
461844e545
9 changed files with 111 additions and 28 deletions
|
@ -19,7 +19,7 @@ class SongListTile extends StatelessWidget {
|
|||
final Widget leading = inAlbum
|
||||
? Center(child: Text('${song.discNumber} - ${song.trackNumber}'))
|
||||
: Image(
|
||||
image: utils.getAlbumImage(null), // FIXME
|
||||
image: utils.getAlbumImage(song.albumArtPath),
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
||||
|
||||
import '../models/album_model.dart';
|
||||
|
@ -36,4 +39,10 @@ class LocalMusicFetcherImpl implements LocalMusicFetcher {
|
|||
.map((SongInfo songInfo) => SongModel.fromSongInfo(songInfo))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> getAlbumArtwork(int id) async {
|
||||
return flutterAudioQuery.getArtwork(
|
||||
type: ResourceType.ALBUM, id: id.toString(), size: const Size(500.0, 500.0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import '../models/album_model.dart';
|
||||
import '../models/artist_model.dart';
|
||||
import '../models/song_model.dart';
|
||||
|
@ -6,4 +8,5 @@ abstract class LocalMusicFetcher {
|
|||
Future<List<ArtistModel>> getArtists();
|
||||
Future<List<AlbumModel>> getAlbums();
|
||||
Future<List<SongModel>> getSongs();
|
||||
Future<Uint8List> getAlbumArtwork(int id);
|
||||
}
|
|
@ -46,6 +46,20 @@ class AlbumModel extends Album {
|
|||
return '$title';
|
||||
}
|
||||
|
||||
AlbumModel copyWith({
|
||||
String artist,
|
||||
String title,
|
||||
int id,
|
||||
int year,
|
||||
String albumArtPath,
|
||||
}) =>
|
||||
AlbumModel(
|
||||
artist: artist ?? this.artist,
|
||||
title: title ?? this.title,
|
||||
id: id ?? this.id,
|
||||
year: year ?? pubYear,
|
||||
albumArtPath: albumArtPath ?? this.albumArtPath);
|
||||
|
||||
AlbumsCompanion toAlbumsCompanion() => AlbumsCompanion(
|
||||
title: Value(title),
|
||||
artist: Value(artist),
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import '../../core/error/failures.dart';
|
||||
import '../../domain/entities/album.dart';
|
||||
|
@ -50,37 +53,73 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
|
|||
|
||||
@override
|
||||
Future<void> updateDatabase() async {
|
||||
_log.info('updataDatabase called');
|
||||
_log.info('updateDatabase called');
|
||||
|
||||
await musicDataSource.deleteAllArtists();
|
||||
final List<ArtistModel> artists = await localMusicFetcher.getArtists();
|
||||
updateArtists();
|
||||
final albumIdMap = await updateAlbums();
|
||||
await updateSongs(albumIdMap);
|
||||
|
||||
for (final ArtistModel artist in artists) {
|
||||
await musicDataSource.insertArtist(artist);
|
||||
}
|
||||
|
||||
await musicDataSource.deleteAllAlbums();
|
||||
final List<AlbumModel> albums = await localMusicFetcher.getAlbums();
|
||||
final Map<int, int> albumIdMap = {};
|
||||
|
||||
for (final AlbumModel album in albums) {
|
||||
final int newAlbumId = await musicDataSource.insertAlbum(album);
|
||||
albumIdMap[album.id] = newAlbumId;
|
||||
}
|
||||
|
||||
final List<SongModel> songs = await localMusicFetcher.getSongs();
|
||||
|
||||
final List<SongModel> songsToInsert = [];
|
||||
for (final SongModel song in songs) {
|
||||
songsToInsert.add(song.copyWith(albumId: albumIdMap[song.albumId]));
|
||||
}
|
||||
await musicDataSource.insertSongs(songsToInsert);
|
||||
|
||||
_log.info('updataDatabase finished');
|
||||
_log.info('updateDatabase finished');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setSongBlocked(Song song, bool blocked) async {
|
||||
await musicDataSource.setSongBlocked(song as SongModel, blocked);
|
||||
}
|
||||
|
||||
Future<void> updateArtists() async {
|
||||
await musicDataSource.deleteAllArtists();
|
||||
final List<ArtistModel> artists = await localMusicFetcher.getArtists();
|
||||
|
||||
for (final ArtistModel artist in artists) {
|
||||
await musicDataSource.insertArtist(artist);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<int, int>> updateAlbums() async {
|
||||
await musicDataSource.deleteAllAlbums();
|
||||
final List<AlbumModel> albums = await localMusicFetcher.getAlbums();
|
||||
final Map<int, int> albumIdMap = {};
|
||||
|
||||
final Directory dir = await getApplicationSupportDirectory();
|
||||
for (final AlbumModel album in albums) {
|
||||
int newAlbumId;
|
||||
|
||||
if (album.albumArtPath == null) {
|
||||
final String albumArtPath = '${dir.path}/${album.id}';
|
||||
final file = File(albumArtPath);
|
||||
final artwork = await localMusicFetcher.getAlbumArtwork(album.id);
|
||||
if (artwork.isNotEmpty) {
|
||||
file.writeAsBytesSync(artwork);
|
||||
final newAlbum = album.copyWith(albumArtPath: albumArtPath);
|
||||
newAlbumId = await musicDataSource.insertAlbum(newAlbum);
|
||||
} else {
|
||||
newAlbumId = await musicDataSource.insertAlbum(album);
|
||||
}
|
||||
} else {
|
||||
newAlbumId = await musicDataSource.insertAlbum(album);
|
||||
}
|
||||
albumIdMap[album.id] = newAlbumId;
|
||||
}
|
||||
|
||||
return albumIdMap;
|
||||
}
|
||||
|
||||
Future<void> updateSongs(Map<int, int> albumIdMap) async {
|
||||
final Directory dir = await getApplicationSupportDirectory();
|
||||
final List<SongModel> songs = await localMusicFetcher.getSongs();
|
||||
|
||||
final List<SongModel> songsToInsert = [];
|
||||
for (final SongModel song in songs) {
|
||||
if (song.albumArtPath == null) {
|
||||
songsToInsert.add(song.copyWith(
|
||||
albumId: albumIdMap[song.albumId],
|
||||
albumArtPath: '${dir.path}/${song.albumId}',
|
||||
));
|
||||
} else {
|
||||
songsToInsert.add(song.copyWith(albumId: albumIdMap[song.albumId]));
|
||||
}
|
||||
}
|
||||
await musicDataSource.insertSongs(songsToInsert);
|
||||
}
|
||||
}
|
||||
|
|
16
pubspec.lock
16
pubspec.lock
|
@ -477,7 +477,7 @@ packages:
|
|||
name: path_provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.14"
|
||||
version: "1.6.18"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -499,6 +499,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.4+1"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -728,6 +735,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.7.3"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -22,11 +22,11 @@ dependencies:
|
|||
just_audio: ^0.4.0
|
||||
|
||||
get_it: ^4.0.2
|
||||
path_provider: ^1.6.18
|
||||
provider: ^4.0.4
|
||||
logging: ^0.11.4
|
||||
moor: ^3.0.2
|
||||
moor_ffi: ^0.5.0
|
||||
path_provider:
|
||||
path:
|
||||
|
||||
mobx: ^1.1.1
|
||||
|
|
|
@ -89,6 +89,7 @@ void main() {
|
|||
extras: {
|
||||
'albumId': ALBUM_ID_3,
|
||||
'blocked': BLOCKED_3.toString(),
|
||||
'discNumber': null,
|
||||
'trackNumber': TRACKNUMBER_3,
|
||||
});
|
||||
|
||||
|
@ -131,6 +132,7 @@ void main() {
|
|||
duration: DURATION_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
present: PRESENT_3,
|
||||
blocked: BLOCKED_3,
|
||||
);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ const String PATH_3 = '/music/parkwaydrive/bottom_feeder.mp3';
|
|||
const int DURATION_3 = 180000;
|
||||
const String ALBUM_ART_PATH_3 = '/music/parkwaydrive/ire.jpg';
|
||||
const int TRACKNUMBER_3 = 7;
|
||||
const bool PRESENT_3 = true;
|
||||
const bool BLOCKED_3 = false;
|
||||
|
||||
const String SONG_TITLE_4 = 'Black Flame';
|
||||
|
@ -36,4 +37,5 @@ const String PATH_4 = '/music/burytomorrow/blackflame.mp3';
|
|||
const int DURATION_4 = 240000;
|
||||
const String ALBUM_ART_PATH_4 = '/music/parkwaydrive/blackflame.jpg';
|
||||
const int TRACKNUMBER_4 = 3;
|
||||
const bool PRESENT_4 = true;
|
||||
const bool BLOCKED_4 = false;
|
Loading…
Add table
Reference in a new issue