2

I have an issue with my RV. I am loading the cover art of an mp3 into a byte array and then use glide to load the byte array into an image (vh.coverArt). However, when I use glide instead of just setting the image with .SetImageBackground(image) glide returns the same picture over and over again.

I know I am giving it different data each time it is called, however only the very first picture is returned into my image each time. This is the whole function where I Bind the ViewHolder in my RV:

 private async Task SetContentAsync(PhotoViewHolder vh, int position)
        {
            string SongName = "";
            string ArtistName = "";
            Bitmap bitmap = null;
            byte[] data = null;

            try
            {
                reader.SetDataSource(mp3Obj[position].Mp3Uri);
            }
            catch { }


            await Task.Run(() => // cause problems with the reload
            {
                SongName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyTitle);
                ArtistName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyArtist);

                data = reader.GetEmbeddedPicture();

                if (data != null)
                {
                    try
                    {
                        bitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length);
                    }
                    catch { }
                }
            });



            ((Activity)ctx).RunOnUiThread(() =>
            {
                vh.SongName.SetTypeface(tf, TypefaceStyle.Normal);
                vh.AristName.SetTypeface(tf, TypefaceStyle.Normal);
                vh.SongName.Text = SongName;
                vh.AristName.Text = ArtistName;

                try
                {
                    if (bitmap != null && data != null)
                    {


                        Glide
                             .With(ctx)
                             .Load(data)
                             .Apply(RequestOptions.CircleCropTransform()).Into(vh.CoverArt);

                        ConvertBitmapToBackground(bitmap, vh, false); // Set As Backgorund, blurry and black ( just sets the variable)

                    }
                    else // because recycler items inherit their shit and if it is altered it just shows views were there shouldnt be any ... 
                    {
                           vh.CoverArt.SetImageResource(Resource.Drawable.btn_musicalnote);
                           ConvertBitmapToBackground(bitmap, vh, true); // Set As Backgorund, blurry and black ( just sets the variable)             
                    }
                }
                catch { }

            });


        }

Am I using Glide incorrectly?

Zoe
  • 27,060
  • 21
  • 118
  • 148
innomotion media
  • 862
  • 11
  • 30

1 Answers1

1

you should set DiskCacheStrategy to NONE and skipMemoryCache to true like this:

Glide.with(DemoActivity.this)
.load(Uri.parse("file://" + imagePath))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);
zaheer ahmed
  • 168
  • 1
  • 2
  • 11
  • This is true. However, on Xamarin: RequestOptions requestOptions = new RequestOptions(); requestOptions.InvokeDiskCacheStrategy(DiskCacheStrategy.None); requestOptions.SkipMemoryCache(true); requestOptions.CircleCrop(); Glide .With(ctx) .Load(data) .Apply(requestOptions) .Into(vh.CoverArt); – innomotion media Dec 14 '18 at 10:56