use of com.lansosdk.videoeditor.BitmapLruCache in project LanSoEditor_advance by LanSoSdk.
the class DisplayFramesActivity method startGetFrames.
/**
* 从这里开始演示.
*/
private void startGetFrames() {
if (isExecuting)
return;
mInfo = new MediaInfo(videoPath);
if (mInfo.prepare() == false || mInfo.isHaveVideo() == false) {
return;
}
isExecuting = true;
/**
* 初始化.
*/
mExtractFrame = new ExtractVideoFrame(DisplayFramesActivity.this, videoPath);
if (mInfo.vWidth * mInfo.vHeight > 960 * 540) {
// 视频分辨率过大,则缩小一倍.
mExtractFrame.setBitmapWH(mInfo.vWidth / 2, mInfo.vHeight / 2);
}
if (mTpye == FRAME_TYPE_25) {
// 25帧, 先检查用 内存释放够,如果不够,再用SD卡来缓存.
mExtractFrame.setExtract25Frame();
long desireSize = mExtractFrame.getBitmapHeight() * mExtractFrame.getBitmapWidth() * 4 * 25;
long cachesize = BitmapLruCache.getMaxCacheSize();
if (desireSize > cachesize) {
mDiskCache = new MemoryDiskCache(getApplication());
} else {
mLruCache = new BitmapLruCache();
}
} else if (mTpye == FRAME_TYPE_60) {
mExtractFrame.setExtract60Frame();
mDiskCache = new MemoryDiskCache(getApplication());
} else {
// 不设置,则默认是全部解码
// 全部解码,则用DiskLruCache
mDiskCache = new MemoryDiskCache(getApplication());
}
if (mDiskCache != null) {
Log.i(TAG, "写入到 硬盘.....");
} else {
Log.i(TAG, "写入到 memory....");
}
/**
* 设置处理完成监听.
*/
mExtractFrame.setOnExtractCompletedListener(new onExtractVideoFrameCompletedListener() {
@Override
public void onCompleted(ExtractVideoFrame v) {
mImageAdapter.notifyDataSetChanged();
}
});
/**
* 设置处理进度监听.
*/
mExtractFrame.setOnExtractProgressListener(new onExtractVideoFrameProgressListener() {
/**
* 当前帧的画面回调,, ptsUS:当前帧的时间戳,单位微秒.
*/
@Override
public void onExtractBitmap(Bitmap bmp, long ptsUS) {
if (mDiskCache != null) {
mDiskCache.pushBitmap(bmp);
count++;
// if(count%10==0){
mImageAdapter.notifyDataSetChanged();
// }
} else if (mLruCache != null) {
mLruCache.pushBitmap(bmp);
count++;
// if(count%10==0){
mImageAdapter.notifyDataSetChanged();
// }
}
}
});
/**
* 开始执行. 或者你可以从指定地方开始解码.
* mExtractFrame.start(10*1000*1000);则从视频的10秒处开始提取.
*/
mExtractFrame.start();
}
Aggregations