Fresco - 来自 ControllerListener 的 onIntermediateImageSet 未被调用

Fresco - onIntermediateImageSet from ControllerListener not being called

我正在尝试逐步加载大尺寸 JPG。我看到 this documentation using Fresco and that's exactly what I want: A blur lazy load effect. I took their code from repo sample 看起来像这样包装:

ImageFormatProgressiveJpegFragment.java

  private void setImageUri(Uri uri) {
    mDebugOutput.setText("");
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
        .setProgressiveRenderingEnabled(mProgressiveRenderingEnabled)
        .build();
    DraweeController controller =
        Fresco.newDraweeControllerBuilder()
            .setImageRequest(request)
            .setRetainImageOnFailure(true)
            .setPerfDataListener(mImagePerfDataListener)
            .setControllerListener(
                new BaseControllerListener<ImageInfo>() {
                  @Override
                  public void onFinalImageSet(
                      String id,
                      @javax.annotation.Nullable ImageInfo imageInfo,
                      @javax.annotation.Nullable Animatable animatable) {
                    if (imageInfo != null) {
                      QualityInfo qualityInfo = imageInfo.getQualityInfo();
                      logScan(qualityInfo, true);
                    }
                  }

                  @Override
                  public void onIntermediateImageSet(
                      String id, @javax.annotation.Nullable ImageInfo imageInfo) {
                    if (imageInfo != null) {
                      QualityInfo qualityInfo = imageInfo.getQualityInfo();
                      logScan(qualityInfo, false);
                    }
                  }

                  @Override
                  public void onIntermediateImageFailed(String id, Throwable throwable) {
                    mDebugOutput.append(
                        String.format(
                            Locale.getDefault(),
                            "onIntermediateImageFailed, %s\n",
                            throwable.getMessage()));
                  }
                })
            .build();
    mSimpleDraweeView.setController(controller);
  }

  private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
    mDebugOutput.append(
        String.format(
            Locale.getDefault(),
            "%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
            mDateFormat.format(new Date(System.currentTimeMillis())),
            isFinalImage ? "final" : "intermediate",
            qualityInfo.isOfGoodEnoughQuality(),
            qualityInfo.isOfFullQuality(),
            qualityInfo.getQuality()));
  }

result 是加载图像时输出的图像信息。

除了部分替换日志外,我的代码看起来是一样的:

MyFrescoActivity.java


private String IMAGE_URL = "https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73726/world.topo.bathy.200406.3x5400x2700.png";

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(IMAGE_URL))
                .setProgressiveRenderingEnabled(true)
                .build();

        DraweeController controller =
                Fresco.newDraweeControllerBuilder()
                        .setImageRequest(request)
                        .setRetainImageOnFailure(true)
                        .setPerfDataListener(this)
                        .setControllerListener(
                                new BaseControllerListener<ImageInfo>() {
                                    @Override
                                    public void onFinalImageSet(
                                            String id,
                                            @Nullable ImageInfo imageInfo,
                                            @Nullable Animatable animatable) {
                                        if (imageInfo != null) {
                                            QualityInfo qualityInfo = imageInfo.getQualityInfo();
                                            logScan(qualityInfo, true);
                                        }
                                    }

                                    @Override
                                    public void onIntermediateImageSet(
                                            String id, @Nullable ImageInfo imageInfo) {
                                        if (imageInfo != null) {
                                            QualityInfo qualityInfo = imageInfo.getQualityInfo();
                                            logScan(qualityInfo, false);
                                        }
                                    }

                                    @Override
                                    public void onIntermediateImageFailed(String id, Throwable throwable) {
                                        Log.i("DraweeUpdate",
                                                String.format(
                                                        Locale.getDefault(),
                                                        "onIntermediateImageFailed, %s\n",
                                                        throwable.getMessage()));
                                    }
                                })
                        .build();
        simpleDraweeView.setController(controller);
    }

    private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
        Log.i("DraweeUpdate", String.format(
                Locale.getDefault(),
                "%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
                "",
                isFinalImage ? "final" : "intermediate",
                qualityInfo.isOfGoodEnoughQuality(),
                qualityInfo.isOfFullQuality(),
                qualityInfo.getQuality()));
    }

我仍然没有在 onIntermediateImageSet 上收到回复。当图像完全加载时,此侦听器上唯一被调用的是 onFinalImageSet 。有人知道发生了什么事吗?

  1. 您确定您的图像管道配置设置为如 Showcase 示例所示的渐进式 Jpeg 吗?
  2. 如果您的图片来自缓存,则可以立即显示。
  3. 同样,如果您的网络速度太快,您将看不到进度。

您可以尝试将模拟器和网络类型设置为 GPRS 进行测试