[Android] Attempt to load embedded artwork directly from media as a last resort
Robert Stone
git at videolan.org
Mon Sep 27 09:28:21 UTC 2021
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Thu Sep 9 21:36:13 2021 -0700| [3ec4c42eb9f189fde8853dd55623faf20bd723cf] | committer: Nicolas Pomepuy
Attempt to load embedded artwork directly from media as a last resort
> https://code.videolan.org/videolan/vlc-android/commit/3ec4c42eb9f189fde8853dd55623faf20bd723cf
---
.../src/org/videolan/vlc/ArtworkProvider.kt | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt b/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt
index afb31feb5..1fffc5c45 100644
--- a/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt
@@ -33,9 +33,14 @@ import android.util.Log
import android.util.LruCache
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
+import org.videolan.libvlc.FactoryManager
+import org.videolan.libvlc.interfaces.IMedia
+import org.videolan.libvlc.interfaces.IMediaFactory
+import org.videolan.medialibrary.MLServiceLocator
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.resources.VLCInstance
import org.videolan.resources.util.getFromMl
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
@@ -210,6 +215,7 @@ class ArtworkProvider : ContentProvider() {
val image = getOrPutImage(mw?.artworkMrl ?: "${mediaId}}") {
runBlocking(Dispatchers.IO) {
var bitmap = if (mw != null) ThumbnailsProvider.obtainBitmap(mw, width) else null
+ if (bitmap == null) bitmap = readEmbeddedArtwork(mw, width)
if (bitmap != null) bitmap = padSquare(bitmap)
if (bitmap == null) bitmap = ctx.getBitmapFromDrawable(R.drawable.ic_no_media, width, width)
return at runBlocking encodeImage(bitmap)
@@ -349,6 +355,24 @@ class ArtworkProvider : ContentProvider() {
return bos.toByteArray()
}
+ /**
+ * Attempt to directly load embedded artwork.
+ */
+ private fun readEmbeddedArtwork(mw: MediaLibraryItem?, width: Int): Bitmap? {
+ if (mw is MediaWrapper && mw.artworkMrl == null && mw.uri != null) {
+ var media: IMedia? = null
+ return try {
+ val libVlc = VLCInstance.getInstance(ctx)
+ val mediaFactory = FactoryManager.getFactory(IMediaFactory.factoryId) as IMediaFactory
+ media = mediaFactory.getFromUri(libVlc, mw.uri).apply { parse() }
+ AudioUtil.readCoverBitmap(Uri.decode(MLServiceLocator.getAbstractMediaWrapper(media).artworkMrl), width)
+ } finally {
+ media?.release()
+ }
+ }
+ return null
+ }
+
/**
* Return a ParcelFileDescriptor from a Bitmap encoded in WEBP format. This function writes the
* compressed data stream directly to the file descriptor with no intermediate byte array.
More information about the Android
mailing list