美文网首页
记录一个Lottie-Android远程加载失败但是zip文件放

记录一个Lottie-Android远程加载失败但是zip文件放

作者: Avalon1 | 来源:发表于2023-11-30 14:06 被阅读0次

原因在于lottie 源码中的这一段。如果 contentType 不满足判断为zip 的条件。会导致他被当做json处理。解析失败

@NonNull
  private LottieResult<LottieComposition> fromInputStream(Context context, @NonNull String url, @NonNull InputStream inputStream, @Nullable String contentType,
      @Nullable String cacheKey) throws IOException {
    FileExtension extension;
    LottieResult<LottieComposition> result;
    if (contentType == null) {
      // Assume JSON for best effort parsing. If it fails, it will just deliver the parse exception
      // in the result which is more useful than failing here.
      contentType = "application/json";
    }
    if (contentType.contains("application/zip") ||
        contentType.contains("application/x-zip") ||
        contentType.contains("application/x-zip-compressed") ||
        url.split("\\?")[0].endsWith(".lottie")) {
      Logger.debug("Handling zip response.");
      extension = FileExtension.ZIP;
      result = fromZipStream(context, url, inputStream, cacheKey);
    } else {
      Logger.debug("Received json response.");
      extension = FileExtension.JSON;
      result = fromJsonStream(url, inputStream, cacheKey);
    }

    if (cacheKey != null && result.getValue() != null && networkCache != null) {
      networkCache.renameTempFile(url, extension);
    }

    return result;
  }

相关文章

网友评论

      本文标题:记录一个Lottie-Android远程加载失败但是zip文件放

      本文链接:https://www.haomeiwen.com/subject/dmsqgdtx.html