Glide gif doesnt play - android

I want to load a gif into an imageview, it is displayed but doesn't start playing. I use this code:
Glide.with(context)
.load("https://media.giphy.com/media/7rj2ZgttvgomY/giphy.gif")
.into(imageView)
I've also tried adding .asGif() but in that case image is not displayed at all. I'm using glide 3.8.0

try this.
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);

In my case I had set the imageview dimensions to match_parent and specifying it in dp did it for me.
Not sure why exactly match_parent doesn't work in a dialog, playing GIFs, probably something to do with the scaling, if this is the case then using scaleType:fitXY should work too

You can also try
Glide
.with(context)
.load(gifUrl)
.asGif()
.error(R.drawable.full_cake)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)`
.into(imageViewGif);

Change your gif your to https://i.giphy.com/media/7rj2ZgttvgomY/giphy.webp
Glide.with(context)
.load("https://i.giphy.com/media/7rj2ZgttvgomY/giphy.webp")
.asGif().into(imageView);
Also you can try GIFView

You can refer to : https://github.com/bumptech/glide/issues/1059
If you don't find it, you can change the lastest version of Gline
repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
compile 'com.github.bumptech.glide:glide:4.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
}
I hope you can find solution.

There is nothing wrong with your code. You could check if you have Internet permission.
<uses-permission android:name="android.permission.INTERNET" />
Your internet speed might be slow and Glide might be taking too much time to load so by that time you could add a placeholder image using :
.placeholder(android.R.color.holo_green_dark)
Or you could add Listner to the Request using
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
})
And see what is the Exception.

Related

How to request again if image download failed using glide

I'm try to download multiple images from server using the Glide
here is code
for (String url : list) {
RequestOptions requestOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL);
Glide.with(this)
.asBitmap()
.load(url).addListener(new RequestListener<Bitmap>() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
Log.e("ProgressCheck", "onResourceReady: " + progress);
return false;
}
})
.apply(requestOptions)
.submit();
}
Code run perfectly but when the downloading image failed (any reason wifi disconnected or server not responding.etc) how to send the same request again??
or is there the better way download multiple images using Glide
I suggest you to make a separate method of loading image via glide.
Here is the pseudo code
private void loadImage(String URL){
// Your Glide code
//Inside onLoadFailed call loadImage() again.
//For number of attempts you can maintain one int and increment that on every attempt.
}
If error or fallback strategies are not useful to you, then in 4.3.0 version you can starting a new request on failure:
Glide.with(fragment)
.load(url)
.error(
Glide.with(fragment)
.load(url))
.into(imageView);
Learn more at https://bumptech.github.io/glide/doc/options.html#starting-a-new-request-on-failure

Load GIF From URL

I tried to get this GIF from a URL like this:
Glide.with(context)
.load("http://artfcity.com/wp-content/uploads/2017/07/tumblr_osmx1ogeOD1r2geqjo1_540.gif")
.into(new GlideDrawableImageViewTarget(imageViewBaby) {
#Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim);
imageViewBaby.setImageDrawable(drawable);
imageViewBaby.invalidate();
imageViewBaby.requestLayout();
}
});
But the GIF will not move or start. It's just like an image! How to solve this issue?
Try this
Add dependency
implementation 'com.github.bumptech.glide:glide:4.4.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'
Gif Loading
Glide.with(this)
.load("http://artfcity.com/wp-
content/uploads/2017/07/tumblr_osmx1ogeOD1r2geqjo1_540.gif")
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.into(imageView);
See this https://github.com/bumptech/glide/issues/2471
As android doesnot support gif files, you can use webview to display the gif file.
Please use .asGif() to load gif images inside your ImageView:
Glide.with(context)
.load(gifUrl)
.asGif()
.diskCacheStrategy(DiskCacheStrategy.SOURCE).override(200, 200)
.into(((GifViewHolder) holder).gifImageView);

Image flickering when Glide loads it

I have a list of image views and some of them will be frequently updated with a fixed url. By appending a timestamp query parameter in the end of the url. It works, but I found when it updates it will also clear the current content. Any way to prevent this?
// the one needed to update with timestamp appended
image += "?"+String.valueOf(System.currentTimeMillis());
Glide.with(mContext.getApplicationContext())
.load(image)
.error(R.drawable.default_avatar)
.centerCrop()
.crossFade()
.into(((VideoViewHolder) holder).img);
// the others don't need to update
Glide.with(mContext.getApplicationContext())
.load(image)
.error(R.drawable.default_avatar)
.centerCrop()
.crossFade()
.into(((VideoViewHolder) holder).img);
Note that the others without timestamp appended are all good.
Try this
Glide
.with(context)
.load(filepath)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.dontAnimate()
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap arg0, GlideAnimation<? super Bitmap> arg1) {
// TODO Auto-generated method stub
holder.mItemView.setImageBitmap(arg0);
}
});
If you're using Glide 3.x and wish to directly display the image without the small crossfade effect, call .dontAnimate() on the Glide request builder:
for more read this : Glide — Placeholders & Fade Animations
Happy coding!!
If you are using Emulator, then this can happens.
Try using a real physical device or change the emulator.

Suddenly Glide is failing to get image from url

Thanks for viewing my question here.
I am using Glide to fetch image from Firebase storage, basically i am using url to get the image from storage. First day it was working fine but suddenly it stopped fetching image. i did not touch the code. I have checked many answer but still i could not fix the issue. Please let me know where i am doing mistake.
This is gradle app file.
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.android.support:support-v4:23.4.0'
This is the Glide code i use in my Adapter java file
Glide.with(context).load(mproduct.get(position).getUrl()).into(viewHolder.pic);
Internet permission is there
<uses-permission android:name="android.permission.INTERNET" />
If it is not loading an image, there must be an error!
Check out the reason using listener:-
Glide.with(context)
.load(mproduct.get(position).getUrl())
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// Here you will get the cause of error...
return true;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
// do something
return true;
}
})
.into(viewHolder.pic);
Please try with Piccaso
You can try below code..
Picasso.with(getApplicationContext()).load(mproduct.get(position).getUrl()).error(R.drawable.demo_image).into(viewHolder.pic);
dont forget to add dependency for Piccasso.

Android Glide: How to download and cache bitmaps?

I am using Glide to download and cache images on Android. Everything works well except the fact that I don't want to load the bitmaps directly into the ImageView, I don't want to have the fade animation, neither image placeholders.
All I want is to create a global method which will help me to download the image all over the application.
public class MyApp extends Application {
public static void downloadImage(String url, final OnImageLoadedCallback callback) {
// And how to implement the listener ?
RequestListener<String, Bitmap> requestListener = new RequestListener<String, Bitmap() {
#Override
public boolean onException(Exception exc, String string, Target<Bitmap> target, boolean isFirstResource) {
callback.onDone(null);
return false;
}
#Override
public boolean onResourceReady(Bitmap bitmap, String string, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
callback.onDone(bitmap);
return false;
}
};
Glide.with(context)
.load(url)
.asBitmap()
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.listener(requestListener);
}
}
The problem is that I don't know how to implement the listener. RequestListener isn't called at all.
Loads in Glide don't start until you make a call to into. The RequestListener interface observes requests, but isn't typically meant for handling results. Instead of using RequestListener, consider having your callback implement the Target interface and pass it in using into.
Alternatively you could just extend SimpleTarget and pass it in to each request in the same way you're trying to use RequestListener:
Target target = Glide.with(context)
...
.into(new SimpleTarget<Bitmap>(width, height) {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
callback.onDone(resource);
}
#Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
callback.onDone(null);
}
});
// At some point later, if you want to cancel the load:
Glide.clear(target);
You will want to provide a width and a height so that Glide can downsample and transform images appropriately. You may also run in to issues with cancellation if you're displaying these Bitmaps in views, in which case I'd strongly recommend making the view available to your loading API and passing the view to into which will handle sizing and cancellation for you.
I use Glide 3.7.0 and download images this way:
it is important to note - it executes asyncroniously
Glide.with(this)
.load(url)
.downloadOnly(new SimpleTarget<File>() {
#Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) {
LOGGER.debug("Photo downloaded");
}
});
When I need to show cached image, I use the same url and DiskCacheStrategy.SOURCE:
Glide.with(this)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);
It is now even simpler on Glide 4.9.0.
Glide.with(this)
.downloadOnly()
.load(url)

Categories

Resources