Commit c3487189 authored by Sébastien Toque's avatar Sébastien Toque
Browse files

Extract embedded album arts into cache, and use them if available

parent a9e16df2
From 333b15549243936ad7c559bf1930f3b358e9a254 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Toque?= <xilasz@gmail.com>
Date: Fri, 22 Jun 2012 23:05:37 +0200
Subject: [PATCH] Android: fix album art extraction
---
src/playlist/art.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/playlist/art.c b/src/playlist/art.c
index 79ca30f..6f8b9db 100644
--- a/src/playlist/art.c
+++ b/src/playlist/art.c
@@ -64,7 +64,11 @@ static char* ArtCacheGetDirPath( const char *psz_arturl, const char *psz_artist,
const char *psz_album, const char *psz_title )
{
char *psz_dir;
+#ifdef __ANDROID__
+ char *psz_cachedir = strdup("/sdcard/Android/data/org.videolan.vlc/cache");
+#else
char *psz_cachedir = config_GetUserDir(VLC_CACHE_DIR);
+#endif
if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
{
--
1.7.9.5
......@@ -651,6 +651,7 @@ jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject th
setString(env, item, "Artist", libvlc_media_get_meta(p_m, libvlc_meta_Artist));
setString(env, item, "Album", libvlc_media_get_meta(p_m, libvlc_meta_Album));
setString(env, item, "Genre", libvlc_media_get_meta(p_m, libvlc_meta_Genre));
setString(env, item, "ArtworkURL", libvlc_media_get_meta(p_m, libvlc_meta_ArtworkURL));
continue;
}
......
......@@ -407,6 +407,7 @@ public class AudioService extends Service {
private Bitmap getCover() {
try {
// try to get the cover from android MediaStore
ContentResolver contentResolver = getContentResolver();
Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, new String[] {
......@@ -427,6 +428,13 @@ public class AudioService extends Service {
if (b != null)
return b;
}
//cover not in MediaStore, trying vlc
String artworkURL = mCurrentMedia.getArtworkURL();
if (artworkURL != null && artworkURL.startsWith("file://"))
return BitmapFactory.decodeFile(Uri.decode(artworkURL).replace("file://", ""));
//still no cover found, looking in folder ...
File f = Util.URItoFile(mCurrentMedia.getLocation());
for (File s : f.getParentFile().listFiles()) {
if (s.getAbsolutePath().endsWith("png") ||
......
......@@ -44,7 +44,7 @@ public class DatabaseManager {
private SQLiteDatabase mDb;
private final String DB_NAME = "vlc_database";
private final int DB_VERSION = 6;
private final int DB_VERSION = 7;
private final int CHUNK_SIZE = 50;
private final String DIR_TABLE_NAME = "directories_table";
......@@ -62,6 +62,7 @@ public class DatabaseManager {
private final String MEDIA_ALBUM = "album";
private final String MEDIA_WIDTH = "width";
private final String MEDIA_HEIGHT = "height";
private final String MEDIA_ARTWORKURL = "artwork_url";
private final String PLAYLIST_TABLE_NAME = "playlist_table";
private final String PLAYLIST_NAME = "name";
......@@ -78,7 +79,7 @@ public class DatabaseManager {
public enum mediaColumn {
MEDIA_TABLE_NAME, MEDIA_PATH, MEDIA_TIME, MEDIA_LENGTH,
MEDIA_TYPE, MEDIA_PICTURE, MEDIA_TITLE, MEDIA_ARTIST, MEDIA_GENRE, MEDIA_ALBUM,
MEDIA_WIDTH, MEDIA_HEIGHT
MEDIA_WIDTH, MEDIA_HEIGHT, MEDIA_ARTWORKURL
}
/**
......@@ -123,7 +124,8 @@ public class DatabaseManager {
+ MEDIA_GENRE + " VARCHAR(200), "
+ MEDIA_ALBUM + " VARCHAR(200), "
+ MEDIA_WIDTH + " INTEGER, "
+ MEDIA_HEIGHT + " INTEGER"
+ MEDIA_HEIGHT + " INTEGER, "
+ MEDIA_ARTWORKURL + " VARCHAR(256)"
+ ");";
db.execSQL(query);
}
......@@ -168,7 +170,7 @@ public class DatabaseManager {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 5 && newVersion == 6) {
if (oldVersion < 7 && newVersion == 7) {
dropMediaTabelQuery(db);
createMediaTabelQuery(db);
}
......@@ -244,6 +246,7 @@ public class DatabaseManager {
values.put(MEDIA_ALBUM, media.getAlbum());
values.put(MEDIA_WIDTH, media.getWidth());
values.put(MEDIA_HEIGHT, media.getHeight());
values.put(MEDIA_ARTWORKURL, media.getArtworkURL());
mDb.replace(MEDIA_TABLE_NAME, "NULL", values);
......@@ -301,7 +304,7 @@ public class DatabaseManager {
do {
count = 0;
cursor = mDb.rawQuery(String.format("SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s LIMIT %d OFFSET %d",
cursor = mDb.rawQuery(String.format("SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s LIMIT %d OFFSET %d",
MEDIA_TIME, //0 long
MEDIA_LENGTH, //1 long
MEDIA_TYPE, //2 int
......@@ -312,7 +315,8 @@ public class DatabaseManager {
MEDIA_ALBUM, //7 string
MEDIA_WIDTH, //8 int
MEDIA_HEIGHT, //9 int
MEDIA_LOCATION, //10 string
MEDIA_ARTWORKURL, //10 string
MEDIA_LOCATION, //11 string
MEDIA_TABLE_NAME,
CHUNK_SIZE,
chunk_count * CHUNK_SIZE), null);
......@@ -323,7 +327,7 @@ public class DatabaseManager {
if (blob != null) {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
String location = cursor.getString(10);
String location = cursor.getString(11);
Media media = new Media(context, location,
cursor.getLong(0),
cursor.getLong(1),
......@@ -334,7 +338,8 @@ public class DatabaseManager {
cursor.getString(6),
cursor.getString(7),
cursor.getInt(8),
cursor.getInt(9));
cursor.getInt(9),
cursor.getString(10));
medias.put(media.getLocation(), media);
picture = null;
......@@ -369,6 +374,7 @@ public class DatabaseManager {
MEDIA_ALBUM, //7 string
MEDIA_WIDTH, //8 int
MEDIA_HEIGHT, //9 int
MEDIA_ARTWORKURL //10 string
},
MEDIA_LOCATION + "=?",
new String[] { location },
......@@ -389,7 +395,8 @@ public class DatabaseManager {
cursor.getString(6),
cursor.getString(7),
cursor.getInt(8),
cursor.getInt(9));
cursor.getInt(9),
cursor.getString(10));
}
cursor.close();
return media;
......
......@@ -85,6 +85,7 @@ public class Media implements Comparable<Media> {
private String mPublisher;
private String mEncodedBy;
private String mTrackID;
private String mArtworkURL;
private final String mLocation;
private String mFilename;
......@@ -124,6 +125,7 @@ public class Media implements Comparable<Media> {
mArtist = Util.getValue(context, track.Artist, R.string.unknown_artist);
mAlbum = Util.getValue(context, track.Album, R.string.unknown_album);
mGenre = Util.getValue(context, track.Genre, R.string.unknown_genre);
mArtworkURL = track.ArtworkURL;
Log.d(TAG, "Title " + mTitle);
Log.d(TAG, "Artist " + mArtist);
Log.d(TAG, "Genre " + mGenre);
......@@ -143,7 +145,7 @@ public class Media implements Comparable<Media> {
public Media(Context context, String location, long time, long length, int type,
Bitmap picture, String title, String artist, String genre, String album,
int width, int height) {
int width, int height, String artworkURL) {
mLocation = location;
mFilename = null;
mTime = time;
......@@ -157,6 +159,7 @@ public class Media implements Comparable<Media> {
mArtist = Util.getValue(context, artist, R.string.unknown_artist);
mGenre = Util.getValue(context, genre, R.string.unknown_genre);
mAlbum = Util.getValue(context, album, R.string.unknown_album);
mArtworkURL = artworkURL;
}
/**
......@@ -279,4 +282,7 @@ public class Media implements Comparable<Media> {
return mTrackID;
}
public String getArtworkURL() {
return mArtworkURL;
}
}
......@@ -28,4 +28,5 @@ public class TrackInfo {
public String Artist;
public String Album;
public String Genre;
public String ArtworkURL;
}
Supports Markdown
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