Commit 71ac8df3 authored by Sébastien Toque's avatar Sébastien Toque

Create cover cache folder if it doesn't exists

parent 8e70d834
......@@ -129,6 +129,8 @@ public class AudioService extends Service {
if(Util.isICSOrLater())
setUpRemoteControlClient();
AudioUtil.prepareCacheFolder();
}
@TargetApi(14)
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment