If you think the Android project MediaCodecVideoPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jasonsoft.mediacodecvideoplayer.cache;
/*fromwww.java2s.com*/import android.graphics.Bitmap;
import android.util.LruCache;
publicclass CacheManager {
privatestaticfinal String TAG = CacheManager.class.getSimpleName();
privatestatic CacheManager sInstance;
private LruCache<String, Bitmap> mMemoryCache;
private CacheManager() {
// Get max available VM memory, exceeding this amount will throw an
// OutOfMemory exception. Stored in kilobytes as LruCache takes an
// int in its constructor.
finalint maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
// Use 1/8th of the available memory for this memory cache.
finalint cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protectedint sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getByteCount() / 1024;
}
};
}
synchronizedpublicstatic CacheManager getInstance() {
if (sInstance == null) {
sInstance = new CacheManager();
}
return sInstance;
}
public LruCache<String, Bitmap> getMemoryCache() {
return mMemoryCache;
}
publicvoid addThumbnailToMemoryCache(String key, Bitmap thumbnail) {
if (getThumbnailFromMemCache(key) == null) {
mMemoryCache.put(key, thumbnail);
}
}
public Bitmap getThumbnailFromMemCache(String key) {
return mMemoryCache.get(key);
}
}