Glide和Picasso不从YouTube加载图片

问题描述 投票:0回答:3

我是ImageView,Picasso,Glide的新手。我想从网址加载图片,我试过Glide和Picasso。他们两个加载图像很好,但如果我尝试从youtube(缩略图)加载图像 - 不加载。 // http://i.ytimg.com/vi/z0NfI2NeDHI/sddefault.jpg - 没有加载

main activity.Java

imageView = findViewById(R.id.image);
videoImg = ""
fetchData.execute(); //returns link for image to videoImg
Glide.with(this)
                .load(videoImg)
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_foreground)
                .into(imageView);
        Picasso.get().load(videoImg).into(imageView);

activity_main.xml中

<ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

logcat的

W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
W/Glide: Load failed for null with size [0x0]
    class com.bumptech.glide.load.engine.GlideException: Received null model
android image picasso android-glide
3个回答
0
投票

我认为你所面临的问题与Glide,Picasso或其他类似的图书馆无关。我尝试使用你使用Glide提供的图像链接,它按预期工作。

我有根据的猜测是,您的设备正在使用某种受限制的网络,因此它会阻止来自/管道端点的请求。如果你从另一个网络连接它将工作得很好。


0
投票

如果您只是想将图像加载到ImageView中,只需使用一个库,那么就说Glide。

  1. 首先看一下你的代码,你应该像这样声明videoImg: videoImg =“http://i.ytimg.com/vi/z0NfI2NeDHI/sddefault.jpg”;
  2. 然后检查您的依赖项,您应该添加正确的依赖项: 实现'com.github.bumptech.glide:glide:4.9.0' annotationProcessor'com.github.bumptech.glide:compiler:4.9.0'

不要忘记将maven Central()添加到buildscript下项目文件中的存储库

  1. 在清单中添加Internet权限: <uses-permission android:name="android.permission.INTERNET"/>

0
投票

嗯,尴尬的情况..我使用自定义AsyncTask返回String(链接到yt图像)(在我的情况下是videoImg)所以我的代码是:

void ShowImage(View v){
    fetchData.execute();
    Glide.with(MainActivity.this)
                .load(videoImg)
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_foreground)
                .into(imageView);
}

所以AsyncTask没有时间下载链接和Glide只是试图加载空字符串..

再次抱歉..

© www.soinside.com 2019 - 2024. All rights reserved.