resolve method
Returns an ImageProvider
for a given NowPlayingTrack
If an image cannot be resolved, or does not need to be for
some reason (e.g. we're happy with the image that has already
been found in the system metadata) resolve
should return null
Implementation
Future<ImageProvider?> resolve(NowPlayingTrack track) async {
if (track.hasImage) return null;
final String query = Uri.encodeQueryComponent([
if (track.artist != null) 'artist:(${_rationalise(track.artist!)})',
if (track.album != null) 'release:(${_rationalise(track.album!)})',
].join(' AND '));
if (query.isEmpty) return null;
print('NowPlaying - image resolution query: $query');
final json = await _getJson('https://musicbrainz.org/ws/2/release?primarytype=album&limit=100&query=$query');
if (json == null) return null;
for (Map<String, dynamic> release in json['releases']) {
if (release['score'] as int >= 100) {
final albumArt = await _getAlbumArt(release['id']);
if (albumArt != null) return albumArt;
}
}
return null;
}