initial support for internal artwork loader
This commit is contained in:
parent
da21f68c10
commit
184d91b5bd
@ -38,10 +38,15 @@ THE SOFTWARE.
|
||||
android:title="@string/idle_timeout_title"
|
||||
android:dependency="use_idle_timeout" />
|
||||
<CheckBoxPreference
|
||||
android:key="disable_cover_art"
|
||||
android:key="coverloader_android"
|
||||
android:title="@string/disable_cover_art_title"
|
||||
android:summary="@string/disable_cover_art_summary"
|
||||
android:defaultValue="false" />
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="coverloader_vanilla"
|
||||
android:title="@string/disable_cover_art_title"
|
||||
android:summary="@string/disable_cover_art_summary"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="double_tap"
|
||||
android:title="@string/double_tap_title"
|
||||
|
@ -1066,7 +1066,7 @@ public class LibraryActivity
|
||||
cover = song.getCover(this);
|
||||
}
|
||||
|
||||
if (Song.mDisableCoverArt)
|
||||
if (Song.mCoverLoadMode == 0)
|
||||
mCover.setVisibility(View.GONE);
|
||||
else if (cover == null)
|
||||
mCover.setImageResource(R.drawable.fallback_cover);
|
||||
|
@ -413,7 +413,10 @@ public final class PlaybackService extends Service
|
||||
mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1"));
|
||||
mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false);
|
||||
mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600) : 0;
|
||||
Song.mDisableCoverArt = settings.getBoolean(PrefKeys.DISABLE_COVER_ART, false);
|
||||
|
||||
Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_ANDROID, true) ? Song.mCoverLoadMode | Song.COVER_MODE_ANDROID : Song.mCoverLoadMode & ~(Song.COVER_MODE_ANDROID);
|
||||
Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true) ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA);
|
||||
|
||||
mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false);
|
||||
mStockBroadcast = settings.getBoolean(PrefKeys.STOCK_BROADCAST, false);
|
||||
mInvertNotification = settings.getBoolean(PrefKeys.NOTIFICATION_INVERTED_COLOR, false);
|
||||
@ -769,8 +772,12 @@ public final class PlaybackService extends Service
|
||||
} else if (PrefKeys.USE_IDLE_TIMEOUT.equals(key) || PrefKeys.IDLE_TIMEOUT.equals(key)) {
|
||||
mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600) : 0;
|
||||
userActionTriggered();
|
||||
} else if (PrefKeys.DISABLE_COVER_ART.equals(key)) {
|
||||
Song.mDisableCoverArt = settings.getBoolean(PrefKeys.DISABLE_COVER_ART, false);
|
||||
} else if (PrefKeys.COVERLOADER_ANDROID.equals(key)) {
|
||||
Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_ANDROID, true) ? Song.mCoverLoadMode | Song.COVER_MODE_ANDROID : Song.mCoverLoadMode & ~(Song.COVER_MODE_ANDROID);
|
||||
Song.mFlushCoverCache = true;
|
||||
} else if (PrefKeys.COVERLOADER_VANILLA.equals(key)) {
|
||||
Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true) ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA);
|
||||
Song.mFlushCoverCache = true;
|
||||
} else if (PrefKeys.NOTIFICATION_INVERTED_COLOR.equals(key)) {
|
||||
updateNotification();
|
||||
} else if (PrefKeys.HEADSET_ONLY.equals(key)) {
|
||||
|
@ -32,7 +32,8 @@ public class PrefKeys {
|
||||
public static final String COVER_PRESS_ACTION = "cover_press_action";
|
||||
public static final String DEFAULT_ACTION_INT = "default_action_int";
|
||||
public static final String DEFAULT_PLAYLIST_ACTION = "default_playlist_action";
|
||||
public static final String DISABLE_COVER_ART = "disable_cover_art";
|
||||
public static final String COVERLOADER_ANDROID = "coverloader_android";
|
||||
public static final String COVERLOADER_VANILLA = "coverloader_vanilla";
|
||||
public static final String DISABLE_LOCKSCREEN = "disable_lockscreen";
|
||||
public static final String DISPLAY_MODE = "display_mode";
|
||||
public static final String DOUBLE_TAP = "double_tap";
|
||||
|
@ -55,6 +55,19 @@ public class Song implements Comparable<Song> {
|
||||
* The number of flags.
|
||||
*/
|
||||
public static final int FLAG_COUNT = 2;
|
||||
/**
|
||||
* Use all cover providers to load cover art
|
||||
*/
|
||||
public static final int COVER_MODE_ALL = 0xF;
|
||||
/**
|
||||
* Use androids builtin cover mechanism to load covers
|
||||
*/
|
||||
public static final int COVER_MODE_ANDROID = 0x1;
|
||||
/**
|
||||
* Use vanilla musics cover load mechanism
|
||||
*/
|
||||
public static final int COVER_MODE_VANILLA = 0x2;
|
||||
|
||||
|
||||
public static final String[] EMPTY_PROJECTION = {
|
||||
MediaStore.Audio.Media._ID,
|
||||
@ -139,21 +152,14 @@ public class Song implements Comparable<Song> {
|
||||
@Override
|
||||
public Bitmap create(LruCacheKey key)
|
||||
{
|
||||
Uri uri = Uri.parse("content://media/external/audio/media/" + key.id + "/albumart");
|
||||
ContentResolver res = mContext.getContentResolver();
|
||||
Log.v("VanillaMusic", "Cache miss on key "+key);
|
||||
try {
|
||||
FileDescriptor fileDescriptor = null;
|
||||
ParcelFileDescriptor parcelFileDescriptor = res.openFileDescriptor(uri, "r");
|
||||
|
||||
if (parcelFileDescriptor != null) {
|
||||
fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
||||
} else {
|
||||
if ((mCoverLoadMode & COVER_MODE_VANILLA) != 0) {
|
||||
String basePath = (new File(key.path)).getParentFile().getAbsolutePath(); // ../ of the currently playing file
|
||||
for (String coverFile: coverNames) {
|
||||
File guessedFile = new File( basePath + "/" + coverFile);
|
||||
if (guessedFile.exists() && !guessedFile.isDirectory()) {
|
||||
Log.v("VanillaMusic", "Found album artwork at "+guessedFile.getAbsolutePath());
|
||||
FileInputStream fis = new FileInputStream(guessedFile);
|
||||
fileDescriptor = fis.getFD();
|
||||
break;
|
||||
@ -161,6 +167,18 @@ Log.v("VanillaMusic", "Cache miss on key "+key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fixme: add shadow folder (/sdcard/.covers/artist/album.jpg)
|
||||
* and checkout why some files load partial (fd vs fis)
|
||||
*/
|
||||
if (fileDescriptor == null && (mCoverLoadMode & COVER_MODE_ANDROID) != 0) {
|
||||
Uri uri = Uri.parse("content://media/external/audio/media/" + key.id + "/albumart");
|
||||
ContentResolver res = mContext.getContentResolver();
|
||||
ParcelFileDescriptor parcelFileDescriptor = res.openFileDescriptor(uri, "r");
|
||||
if (parcelFileDescriptor != null)
|
||||
fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
||||
}
|
||||
|
||||
if (fileDescriptor != null) {
|
||||
BitmapFactory.Options bopts = new BitmapFactory.Options();
|
||||
bopts.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
@ -175,6 +193,7 @@ Log.v("VanillaMusic", "Cache miss on key "+key);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// no cover art found
|
||||
Log.v("VanillaMusic", "Loading coverart for "+key+" failed with exception "+e);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -208,9 +227,14 @@ Log.v("VanillaMusic", "Cache miss on key "+key);
|
||||
private static CoverCache sCoverCache = null;
|
||||
|
||||
/**
|
||||
* If true, will not attempt to load any cover art in getCover()
|
||||
* Bitmask on how we are going to load coverart
|
||||
*/
|
||||
public static boolean mDisableCoverArt = false;
|
||||
public static int mCoverLoadMode = 0;
|
||||
|
||||
/**
|
||||
* We will evict our own cache if set to true
|
||||
*/
|
||||
public static boolean mFlushCoverCache = false;
|
||||
|
||||
/**
|
||||
* Id of this song in the MediaStore
|
||||
@ -323,12 +347,17 @@ Log.v("VanillaMusic", "Cache miss on key "+key);
|
||||
*/
|
||||
public Bitmap getCover(Context context)
|
||||
{
|
||||
if (mDisableCoverArt || id == -1 || (flags & FLAG_NO_COVER) != 0)
|
||||
if (mCoverLoadMode == 0 || id == -1 || (flags & FLAG_NO_COVER) != 0)
|
||||
return null;
|
||||
|
||||
if (sCoverCache == null)
|
||||
sCoverCache = new CoverCache(context.getApplicationContext());
|
||||
|
||||
if (mFlushCoverCache) {
|
||||
mFlushCoverCache = false;
|
||||
sCoverCache.evictAll();
|
||||
}
|
||||
|
||||
LruCacheKey key = new LruCacheKey(id, artistId, albumId, path);
|
||||
Bitmap cover = sCoverCache.get(key);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user