【问题标题】:Show .gif from Firebase Storage link从 Firebase 存储链接显示 .gif
【发布时间】:2018-07-28 23:57:15
【问题描述】:

我的 Firebase 存储中有 .gif 文件的链接

String gifUrl = "https://firebasestorage.googleapis.com/v0/b/rokitskiydev-a18ca.appspot.com/o/WF%2F10-16-02-Digital-15.gif?alt=media&token=0354f6e6-4292-4911-9302-49281d293a80";

我尝试使用 Picasso 和 Glide。但我只能显示这个 gif 的图像。

GlideApp.with(context).load(gifUrl).into(ImageView);

如果我得到另一个链接,一个例子http://i.imgur.com/1ALnB2s.gif 没关系!

我该怎么做?

【问题讨论】:

  • 不要从firebase粘贴整个URL,只需从datasnapshot的getDownloadUrl方法中获取downloadurl(如果您的图像存储在数据库中)
  • @GastónSaillén 此链接返回 getDownloadUrl() (downloadUrl = taskSnapshot.getDownloadUrl().toString();)
  • 如果你去firebase存储找到文件,它有另一个url?
  • @GastónSaillén no

标签: android gif android-glide


【解决方案1】:

获取 gif 的 downloadUrl,然后使用它通过 Glide 加载 gif。

ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(downloadUrl).into(imageViewTarget);

对于较新版本的 Glide,试试这个:

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

【讨论】:

  • 我使用'com.github.bumptech.glide:glide:4.6.1'。我没有 GlideDrawableImageViewTarget
  • 已编辑答案。你现在可以试试
  • 问题不在于滑行,问题只是 OP 所说的 url
  • @GastónSaillén 但我看到这个 gif 的第一帧。它不是动画的。
【解决方案2】:

正如 Glide 文档所说,

您可以使用.asGif() 强制库加载动画 gif,如果不加载则失败:

Glide.with(activity).load(gifUrl).asGif().into(view);

试试这个

查看文档:https://futurestud.io/tutorials/glide-displaying-gifs-and-videos

正如 FirebaseDoc 所说,您可以这样做以通过滑行加载图像/gif

首先在你的 build.gradle 中声明这个

dependencies {
    // FirebaseUI Storage only
    compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}

然后

这将使用 firebase 加载您的图像

// Reference to an image file in Firebase Storage
StorageReference storageReference = ...;

// ImageView in your Activity
ImageView imageView = ...;

// Load the image using Glide
Glide.with(this /* context */)
        .using(new FirebaseImageLoader())
        .load(storageReference)
        .into(imageView);

如果您需要图像/gif 文件的 url,您可以这样做

storageRef.child("your/firebase/imagepath.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            // Got the download URL for 'users/me/profile.png'
            Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
            generatedFilePath = downloadUri.toString(); /// The string(file link) that you need
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
        }
    });

【讨论】:

  • Glide.with(context).load(watchFace.getImageUrl()) .asGif() // 无法解析 .into(vh.faceImageView);
  • 阅读 asGif 做什么,它会检查您是否正在尝试加载 gif 或图像
  • 另外,如果您的其他链接有效,则可能是由于 firebase 链接
  • 在 .load 之后添加这个 .apply(new RequestOptions() .placeHolder())
  • 另外,检查你是否至少有这个编译你使用 asGif() 'com.github.bumptech.glide:glide:3.7.0'
猜你喜欢
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 2021-03-02
  • 2020-09-25
  • 2019-10-04
  • 2020-12-19
  • 1970-01-01
  • 2020-10-20
相关资源
最近更新 更多