[Android] src: Show embedded art from media as well

Edward Wang git at videolan.org
Thu Jun 28 20:50:20 CEST 2012


android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Jun 28 14:45:46 2012 -0400| [c00e6f2a8cad31763af8639b03c7e2686972bdf9] | committer: Edward Wang

src: Show embedded art from media as well

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=c00e6f2a8cad31763af8639b03c7e2686972bdf9
---

 vlc-android/src/org/videolan/vlc/AudioService.java |   34 +++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index e057500..73aed95 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -21,6 +21,8 @@
 package org.videolan.vlc;
 
 import java.io.File;
+import java.math.BigInteger;
+import java.security.MessageDigest;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -433,8 +435,38 @@ public class AudioService extends Service {
 
             //cover not in MediaStore, trying vlc
             String artworkURL = mCurrentMedia.getArtworkURL();
-            if (artworkURL != null && artworkURL.startsWith("file://"))
+            final String cacheDir = "/sdcard/Android/data/org.videolan.vlc/cache";
+            if (artworkURL != null && artworkURL.startsWith("file://")) {
                 return BitmapFactory.decodeFile(Uri.decode(artworkURL).replace("file://", ""));
+            } else if(artworkURL != null && artworkURL.startsWith("attachment://")) {
+                // Decode if the album art is embedded in the file
+                String mArtist = mCurrentMedia.getArtist();
+                String mAlbum = mCurrentMedia.getAlbum();
+
+                /* Parse decoded attachment */
+                if( mArtist.length() == 0 || mAlbum.length() == 0 ||
+                    mArtist.equals(VLCApplication.getAppContext().getString(R.string.unknown_artist)) ||
+                    mAlbum.equals(VLCApplication.getAppContext().getString(R.string.unknown_album)) )
+                {
+                    /* If artist or album are missing, it was cached by title MD5 hash */
+                    MessageDigest md = MessageDigest.getInstance("MD5");
+                    byte[] binHash = md.digest((artworkURL + mCurrentMedia.getTitle()).getBytes("UTF-8"));
+                    /* Convert binary hash to normal hash */
+                    BigInteger hash = new BigInteger(1, binHash);
+                    String titleHash = hash.toString(16);
+                    while(titleHash.length() < 32) {
+                        titleHash = "0" + titleHash;
+                    }
+                    /* Use generated hash to find art */
+                    artworkURL = cacheDir + "/art/arturl/" + titleHash + "/art.png";
+                } else {
+                    /* Otherwise, it was cached by artist and album */
+                    artworkURL = cacheDir + "/art/artistalbum/" + mArtist + "/" + mAlbum + "/art.png";
+                }
+
+                Log.v(TAG, "artworkURL (calculated) = " + artworkURL);
+                return BitmapFactory.decodeFile(artworkURL);
+            }
 
             //still no cover found, looking in folder ...
             File f = Util.URItoFile(mCurrentMedia.getLocation());



More information about the Android mailing list