【发布时间】:2017-01-18 22:39:45
【问题描述】:
大家好,我的项目有一个需求。
我需要在完成该 gif 动画后显示一个 gif 文件我需要显示其他 gif 文件
例如:我的第一个 gif 动画时间是 10 秒,所以在完成 10 秒后我需要用 5 秒播放其他 gif,依此类推。
我能够获得 gif 动画时间,但是如果我的 gif 动画时间是 10 秒,则 gif 渲染需要很长时间才能播放 gif,然后大约需要 15-20 秒才能播放 播放整个 gif
我正在使用 Glide 库
我从 getGifDurationTime 获取 gif 持续时间,然后 onResourceReady 我安排了一个可运行的到完成时间 但是我的runnable在gif动画完成完成之前执行。实际上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);
【问题讨论】:
-
你能解决这个问题吗@Vishal Gaur ??
-
@DRYBeliever 试试这个github.com/koral--/android-gif-drawable
-
:P Dude...使用相同的...您在 Glide 中找到任何解决方法吗?
标签: android animation gif android-glide