Merge pull request #175 from pa4/local-album-art

Try to use locally stored Album Art files
This commit is contained in:
Tibor Kaputa 2018-10-11 13:46:20 +02:00 committed by GitHub
commit a140bc2cee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -642,6 +642,29 @@ 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) {
try {
val albumArtFilePath = songParentDirectory.toString() + File.separator + albumArtFile;
if (File(albumArtFilePath).exists()) {
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)
} else {
bitmap
}
return Pair(resultBitmap, true)
}
}
} catch (e: Exception) {
}
}
}
return Pair(resources.getColoredBitmap(R.drawable.ic_headset, config.textColor), false)
}