Skip to content

Commit

Permalink
fix: notification artwork not falling back to folder cover
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jan 18, 2025
1 parent 6eb266e commit ad92592
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,9 @@ extension TrackToAudioSourceMediaItem on Selectable {
MediaItem toMediaItem(int currentIndex, int queueLength, Duration? duration) {
final tr = track.toTrackExt();
final artist = tr.originalArtist == '' ? UnknownTags.ARTIST : tr.originalArtist;
final imagePage = tr.pathToImage;
final imagePath = tr.pathToImage;
String? imagePathToUse = File(imagePath).existsSync() ? imagePath : null;
imagePathToUse ??= Indexer.inst.getFallbackFolderArtworkPath(folderPath: tr.folderPath);
return MediaItem(
id: tr.path,
title: tr.title,
Expand All @@ -2012,7 +2014,7 @@ extension TrackToAudioSourceMediaItem on Selectable {
album: tr.hasUnknownAlbum ? '' : tr.album,
genre: tr.originalGenre,
duration: duration ?? Duration(milliseconds: tr.durationMS),
artUri: Uri.file(File(imagePage).existsSync() ? imagePage : AppPaths.NAMIDA_LOGO_MONET),
artUri: Uri.file(imagePathToUse ?? AppPaths.NAMIDA_LOGO_MONET),
);
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ class Indexer<T extends Track> {

bool imageObtainedBefore(String imagePath) => _artworksMap[imagePath] != null || _artworksMapFullRes[imagePath] != null;

String? getFallbackFolderArtworkPath({required String folderPath}) {
String? cover = this.allFolderCovers[folderPath];
if (cover == null && folderPath.endsWith(Platform.pathSeparator)) {
try {
folderPath = folderPath.substring(0, folderPath.length - 1);
cover = this.allFolderCovers[folderPath];
} catch (_) {}
}
return cover;
}

/// {imagePath: (TrackExtended, id)};
final _backupMediaStoreIDS = <String, (Track, int)>{};
final artworksMap = <String, Uint8List?>{};
Expand Down
9 changes: 1 addition & 8 deletions lib/ui/widgets/artwork.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,7 @@ class _ArtworkWidgetState extends State<ArtworkWidget> with LoadingItemsDelayMix
}

if (_imagePath == null && widget.track != null && widget.fallbackToFolderCover) {
String folderPath = widget.track!.folderPath;
String? cover = Indexer.inst.allFolderCovers[folderPath];
if (cover == null && folderPath.endsWith(Platform.pathSeparator)) {
try {
folderPath = folderPath.substring(0, folderPath.length - 1);
cover = Indexer.inst.allFolderCovers[folderPath];
} catch (_) {}
}
final cover = Indexer.inst.getFallbackFolderArtworkPath(folderPath: widget.track!.folderPath);
if (cover != null && mounted) setState(() => _imagePath = cover);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.9.2-beta+250118221
version: 4.9.2-beta+250118223

environment:
sdk: ">=3.6.0 <4.0.0"
Expand Down

0 comments on commit ad92592

Please sign in to comment.