From 1a7c366c20983b446e49bc4e452692a4f3204adb Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 11 Oct 2018 13:51:25 +0200 Subject: [PATCH] updating the way files as cover art are fetched --- .../musicplayer/services/MusicService.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index e2479ce4..424bf0bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -643,17 +643,17 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } if (song != null) { - val songParentDirectory = File(song.path).parentFile; - val albumArtFiles = arrayOf("folder.jpg", "Folder.jpg", "AlbumArt.jpg") - for (albumArtFile in albumArtFiles) { + val songParentDirectory = File(song.path).parent.trimEnd('/') + val albumArtFiles = arrayListOf("folder.jpg", "albumart.jpg", "cover.jpg") + albumArtFiles.forEach { try { - val albumArtFilePath = songParentDirectory.toString() + File.separator + albumArtFile; - if (File(albumArtFilePath).exists()) { - val bitmap = BitmapFactory.decodeFile(albumArtFilePath); + val albumArtFilePath = "$songParentDirectory/$it" + if (getDoesFilePathExist(albumArtFilePath)) { + val bitmap = BitmapFactory.decodeFile(albumArtFilePath) if (bitmap != null) { val resultBitmap = if (bitmap.height > mCoverArtHeight * 2) { val ratio = bitmap.width / bitmap.height.toFloat() - Bitmap.createScaledBitmap(bitmap, (mCoverArtHeight * ratio * 2).toInt(), mCoverArtHeight * 2, false) + Bitmap.createScaledBitmap(bitmap, (mCoverArtHeight * ratio).toInt(), mCoverArtHeight, false) } else { bitmap }