大家好,我的项目都有要求。
我需要在完成gif动画后显示一个gif文件,我需要显示其他gif文件
ex:我的第一个gif动画时间是10秒,所以在完成10秒后我需要用5秒钟播放其他gif,依此类推。
我能够获得gif动画时间,但是如果我的gif动画时间是10秒,那么gif渲染花了很多时间来播放gif然后需要大约15-20秒 玩全gif
我正在使用 Glide 库
我从getGifDurationTime获得gif持续时间,之后onResourceReady我安排了一个runnable到finishTime 但我的runnable执行之前gif animate完成。实际runnable是在正确的时间执行但系统播放gif非常慢的速率
public static int getGifDurationTime(File file){
InputStream is = null;
try {
is = new FileInputStream(file);
Movie movie = Movie.decodeStream(is);
int duration = movie.duration();
return duration;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Movie movie = Movie.decodeStream(is);
int duration = movie.duration();
return 0;
}
Runnable runnable = new Runnable() {
@Override
public void run() {
//code to show next gif
}
};
File file = new File(android.os.Environment.getExternalStorageDirectory(), GiftManager.FOLDER_NAME+"/"+fileName);
int finishTime = getGifDurationTime(file);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(giftImageView) {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
super.onResourceReady(resource, animation);
handler.postDelayed(runnable, finishTime);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
}
};
Glide.with(context).load(file).into(imageViewTarget);
答案 0 :(得分:0)
您可以尝试这样:
Glide.with(getApplicationContext()).asGif()
.load(R.drawable.source)
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.into(ImageViewObject);