Ashish Virani
Ashish Virani

Reputation: 192

Image load fail using Picasso,Glide,Image Loader ,Universal Image Loader

i have creating Hindi video song application, but video thumb can't display in video list. (Single image are loaded but multiple image array can't load.)

using multiple image loader library but doesn't load image:

enter image description here

Glide:

implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'


Glide .with(viewHolder.icon_1.getContext())
            .load(((AppModelicon) this.b.get(i)).getThumnail())
            .into(viewHolder.icon_1)  ;

Glide.with(MainActivity.this)
            .load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
            .placeholder(R.drawable.ic_menu_camera)
            .error(R.drawable.ic_menu_gallery)
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    // log exception
                    Log.e("TAG", "Error loading image", e);
                    return false; // important to return false so the error placeholder can be placed
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                    return false;
                }
            })
            .into(viewHolder.icon_1);

Picasso:

implementation 'com.squareup.picasso:picasso:2.+'

Picasso.get()
            .load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
            .resize(50, 50)
            .centerCrop()
            .into(viewHolder.icon_1);

using request manager with glide :

RequestManager requestManager = Glide.with(a)
            .applyDefaultRequestOptions(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
            .applyDefaultRequestOptions(RequestOptions.placeholderOf(R.drawable.ic_menu_camera));
                requestManager
            .applyDefaultRequestOptions(RequestOptions.skipMemoryCacheOf(true));
                requestManager.load(pathToFile)
            .into(viewHolder.icon_1);

background task method use :

String pathToFile = this.b.get(i).getThumnail();
DownloadImageWithURLTask downloadTask = new DownloadImageWithURLTask(viewHolder.icon_1);
downloadTask.execute(pathToFile);

public class DownloadImageWithURLTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImageWithURLTask(ImageView bmImage) {
        this.bmImage = bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String pathToFile = urls[0];
        Bitmap bitmap = null;
        try {
            InputStream in = new java.net.URL(pathToFile).openStream();
            bitmap = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return bitmap;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}

Please help me how to solve this issue.

Upvotes: 2

Views: 832

Answers (4)

Hitesh Dhamshaniya
Hitesh Dhamshaniya

Reputation: 2182

If you are load image in recyclerview, below code might help you out.

@Override
public void onBindViewHolder(final ViewHolder holder, int position)
{
    Glide.with(this.context)
            .load(urls.get(position))
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(holder.getImage());
}

for more full tutorial you can visit https://ledron.github.io/RecyclerView/

Upvotes: 3

Nik
Nik

Reputation: 2060

I am able to load your image url using glide:

implementation 'com.github.bumptech.glide:glide:4.9.0'

Glide.with(this@MainActivity)
                .load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher)
                .into(imageView)

Upvotes: 0

Ankit Jain
Ankit Jain

Reputation: 30

remove the below line in dependency

annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

Upvotes: 0

nirazverma
nirazverma

Reputation: 1071

Dont pass MainActivity.this as context its always wrong..

try this

//in activity
Glide.with(this) 
       .load("https://pbs.twimg.com/profile_images/1123379185764917248/On9ZnfVh.png")
       .into(imageView)

//in Fragments
Glide.with(view.context)
  .load("url")
  .into(imageView)

replace .load("url") and "imageView" with your own.

Upvotes: 0

Related Questions