[Android] Create cover cache folder if it doesn't exists
Sébastien Toque
git at videolan.org
Mon Oct 8 23:18:22 CEST 2012
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Mon Oct 8 23:16:52 2012 +0200| [71ac8df37b3b2a21821f2b7e25f373922c73d61d] | committer: Sébastien Toque
Create cover cache folder if it doesn't exists
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=71ac8df37b3b2a21821f2b7e25f373922c73d61d
---
vlc-android/src/org/videolan/vlc/AudioService.java | 2 ++
.../src/org/videolan/vlc/gui/audio/AudioUtil.java | 20 +++++++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 552074e..6c48dc0 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -129,6 +129,8 @@ public class AudioService extends Service {
if(Util.isICSOrLater())
setUpRemoteControlClient();
+
+ AudioUtil.prepareCacheFolder();
}
@TargetApi(14)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index 179a792..59cb794 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -53,6 +53,10 @@ public class AudioUtil {
public final static String TAG = "VLC/AudioUtil";
+ @SuppressLint("SdCardPath")
+ public final static String CACHE_DIR = "/sdcard/Android/data/org.videolan.vlc/cache";
+ public final static String COVER_DIR = CACHE_DIR + "/covers/";
+
public static void setRingtone( Media song, Activity activity){
File newringtone = Util.URItoFile(song.getLocation());
ContentValues values = new ContentValues();
@@ -74,6 +78,12 @@ public class AudioUtil {
);
}
+ public static void prepareCacheFolder() {
+ File file = new File(COVER_DIR);
+ if (!file.exists())
+ file.mkdirs();
+ }
+
private static Bitmap getCoverFromMediaStore(Context context, Media media) {
ContentResolver contentResolver = context.getContentResolver();
Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
@@ -100,10 +110,8 @@ public class AudioUtil {
return null;
}
- @SuppressLint("SdCardPath")
private static Bitmap getCoverFromVlc(Context context, Media media) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String artworkURL = media.getArtworkURL();
- 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://")) {
@@ -126,10 +134,10 @@ public class AudioUtil {
titleHash = "0" + titleHash;
}
/* Use generated hash to find art */
- artworkURL = cacheDir + "/art/arturl/" + titleHash + "/art.png";
+ artworkURL = CACHE_DIR + "/art/arturl/" + titleHash + "/art.png";
} else {
/* Otherwise, it was cached by artist and album */
- artworkURL = cacheDir + "/art/artistalbum/" + mArtist + "/" + mAlbum + "/art.png";
+ artworkURL = CACHE_DIR + "/art/artistalbum/" + mArtist + "/" + mAlbum + "/art.png";
}
return BitmapFactory.decodeFile(artworkURL);
@@ -147,7 +155,6 @@ public class AudioUtil {
return null;
}
- @SuppressLint("SdCardPath")
public synchronized static Bitmap getCover(Context context, Media media, int width) {
Bitmap cover = null;
String cachePath = null;
@@ -155,8 +162,7 @@ public class AudioUtil {
try {
// try to load from cache
int hash = MurmurHash.hash32(media.getArtist()+media.getAlbum());
- cachePath = "/sdcard/Android/data/org.videolan.vlc/cache/covers/" +
- (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
+ cachePath = COVER_DIR + (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
cover = readBitmap(cachePath);
if (cover != null)
return cover;
More information about the Android
mailing list