I'm using Glide to load thumbnail from videos but it doesn't seem to be working on my app. The ImageView is just empty for some reason.
Glide.with(context)
.load(url)
.asBitmap()
.thumbnail(0.1f)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(target);
I added a listener, so I can figure out what is wrong but the Exception thrown is null.
I tried using ThumbnailUtils using the same url because I thought there might be something wrong with it but the thumbnail loads fine.
Anyone experiencing the same? I'm using a Nexus 7 (6.0.1)
Even i stumbled upon the same situation. Somehow from the uri its not loading the image unless create a file instance using local file path. So to make it work i used it like below
Glide.with(mContext).load(Uri.fromFile(new File(path)).into(icon);
In the doc they are using the same approach. You can refer here : Glide - Videos
Apart from that i also noticed unusual behaviour of using the cache. If you are using cache strategy as DiskCacheStrategy.ALL or DiskCacheStrategy.SOURCE it doesn't load the thumbnail but if i am using DiskCacheStrategy.RESULT it works. Hope it helps
As explained in Glide documentation, this feature is only available for videos stored locally on the device.
Also, you should use a path like /storage/emulated/0/Pictures/example_video.mp4. Adding file:/// before this path won't work out either.
You can find more informations here : https://futurestud.io/blog/glide-displaying-gifs-and-videos
Cheers !
You can use override, which surely works:
Glide.with(context)
.load(url)
.crossFade()
.override(width, height)
.into(imageView);
Glide.with(mcontext)
.applyDefaultRequestOptions(RequestOptions.centerCropTransform()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE))
.load(videourl)
.into(thumbnailimg);
Try using this code
#BindingAdapter("videoThumbnailFromUrl")
fun setImageFromVideoUrl(imageView: ImageView, url: String) {
val thumb = 10000L
val options = RequestOptions().frame(thumb)
Glide.with(imageView.context).load(url).apply(options).placeholder(R.drawable.place_holder).into(imageView)
}
Related
Hi I am using Glide to load image and after following many posts I tried to implement Glide caching using
RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
Glide.with(mContext)
.load(imageUrl)
.transition(ImageUtil.crossFadeTransition())
.apply(ImageUtil.requestOptionsForSlider())
.listener(glideRequestListner)
.into(imageView)
My knowledge is that if I use diskCacheStrategy(DiskCacheStrategy.ALL) then the above Glide image loading code will automatically use cache if available, or download if not, right?
But I see everytime the code is called, (checking my internet speed meter) that it is always fetching/downloading from the given url (even though I can see the app memory size is increasing).
I even tried this code also-
val future: FutureTarget<File> = Glide.with(mContext)
.load(imageUrl)
.downloadOnly(500, 500)
Nothing seems to work
What should I do so that Glide uses cache if available?What is wrong with my conception about the caching implementation? Any help is very much appreciated!
Are you sure it is downloading again ? did you try disabling internet just before loading the images ?
Otherwise, is your image URL always the same for the same image ? (as Glide uses it as a cache key).
You can use this in the following calls to check if images are in cache:
Glide.with(fragment)
.load(url)
.onlyRetrieveFromCache(true)
.into(imageView);
The image file is downloaded from the server and always save to the same file name.
So in earlier version of glide, i have been tested with
Uri uri = Uri.fromFile(new File(downloadPath));
GlideApp.with(this)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mDownloadImageView);
It seems work for the file with the same name when its image changes. The offical document Glide Caching mentioned like above.
But now in Glide 4.4.0, i used this code again and it is not working. I need to add the signature like below:
Uri uri = Uri.fromFile(new File(downloadPath));
GlideApp.with(this)
.load(uri)
.signature(new ObjectKey(System.currentTimeMillis()))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mDownloadImageView);
After adding the signature key, then it works.
Does anyone met the same scenario? DiskcacheStrategy None and skip memory cache true as no effect at all to me.
You have to use the RequestOptions now.
Glide.with(this).load(imageResource)
.apply(RequestOptions()
.placeholder(R.drawable.ic_no_profile_image)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.dontAnimate())
.into(profileImageView)
Yes, I have the same problem.
I have to use signature with diskCacheStrategy() set to NONE and skipMemoryCache() set to true if I want to refresh image every time.
Another problem is that if I use diskCacheStrategy() set to ALL with some signature (in order to force cache refresh on some occasions) - it is not working. Signature is changing every time but Glide always loads image from cache and doesn't want to refresh it.
It was working great on Glide v3 and stopped working correctly after upgrading to v4.
I am trying to load an image into an ImageView using the Glide library. The URL that I pass into the load() method points to an endpoint ('/api/user/5/logo'), which then returns the image. For some reason this doesn't seem to work.
However if I pass a URL that points directly to an image ('www.example.com/logo.png'), it works perfectly.
How do I get Glide to work perfectly with the required web service?
To recap, this works:
Glide.with(getContext())
.load("www.example.com/content/logo.png")
.centerCrop()
.placeholder(R.drawable.mark)
.into(imageView);
.. and this doesn't:
Glide.with(getContext())
.load("www.example.com/api/user/5/logo")
.centerCrop()
.placeholder(R.drawable.mark)
.into(imageView);
Any help would be greatly appreciated.
Try with this:
Glide.with(getContext())
.load("http://www.example.com/api/user/5/logo").centerCrop().into(imageview)
I am using picasso library in my project to fetch url images from the server into my ImageView, but unfortunately picasso loading the previously cached images from disc instead of loading the new images from url. Please find the below piece of code for your reference.
Picasso.with (ImageActivity.this)
.load(url)
.placeholder (R.drawable.default_user)
.error (R.drawable.default_user)
.into(imgUser);
I have also tried the solutions like:
Picasso.with(ImageActivity.this).invalidate(url);
and
Picasso.with (ImageActivity.this)
.load(url).memoryPolicy(MemoryPolicy.NO_CACHE)
.placeholder (R.drawable.default_user)
.error (R.drawable.default_user)
.into(imgUser);
But nothing is working for me. Kindly help me to resolve my issues.
Thanks in advance.
Try :
Picasso.with(mContext)
.load(URL)
.memoryPolicy(MemoryPolicy.NO_CACHE )
.networkPolicy(NetworkPolicy.NO_CACHE)
.error(R.drawable.xxx)
.into(xx);
I know there's already an answer but after trying a few ways I figured out a very simple way:
Check if the image is null - if it is not - then load the image with Picasso-like that:
if(vImage.getDrawable() == null)
Picasso.with(context).load(URL).into(vImage);
Hope this helped someone.
im using picasso library to load images.
However in my application, users can have profile pictures and the link for the image is constant... Picasso has no clue that the image has changed...
I tried using : .skipMemoryCache() but it wasn't an ideal solution...
Is there a way to check if there's a new picture in the same link using picasso? Thanks!
Apparently, there is no API in the current (2.3.2) version of Picasso to achieve this (but it is a work in progress - see this bug).
That aside, if you have control of the server side, you may want to think about your design decision to provide the changing profile picture at a constant URL.
An alternative would be: Include the current profile picture URL in the profile information you retrieve. This way, your cache can use the cached image - and as soon as the profile information provides a new URL, Picasso will fetch it. In all other cases, Picasso can leverage the cache.
I got the answer from this link
change your URL as shown below:
String imageurl = url + "?time=" + System.currentTimeMillis();
Picasso.with(getContext()).load(imageurl).into(imageView);
this worked for me. thanks
Picasso.with(context)
.load(url)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.fit()
.placeholder(YOUR PLACE HOLDER RESOURCE)
.centerCrop()
.into(imageView);
One solution is to invalidate the cache like so
Picasso.with(context).invalidate(imagePath);
The other way to force download the image which then is cached for subsequent use as mentioned in the code.
Picasso.with(context)
.load(imagePath)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(userAvatar);