示例#1
0
  @Override
  public Future<BitmapInfo> loadBitmap(Ion ion, String uri, int resizeWidth, int resizeHeight) {
    if (!uri.startsWith(ContentResolver.SCHEME_FILE)) return null;

    final File file = new File(URI.create(uri));

    MediaFile.MediaFileType type = MediaFile.getFileType(file.getAbsolutePath());
    if (type == null || !MediaFile.isVideoFileType(type.fileType)) return null;

    final SimpleFuture<BitmapInfo> ret = new SimpleFuture<BitmapInfo>();
    Ion.getBitmapLoadExecutorService()
        .execute(
            new Runnable() {
              @Override
              public void run() {
                if (ret.isCancelled()) {
                  //                    Log.d("VideoLoader", "Bitmap load cancelled (no longer
                  // needed)");
                  return;
                }
                try {
                  Bitmap bmp = createVideoThumbnail(file.getAbsolutePath());
                  if (bmp == null) throw new Exception("video bitmap failed to load");
                  BitmapInfo info = new BitmapInfo();
                  info.bitmaps = new Bitmap[] {bmp};
                  info.loadedFrom = LoaderEmitter.LOADED_FROM_CACHE;
                  ret.setComplete(info);
                } catch (Exception e) {
                  ret.setComplete(e);
                }
              }
            });
    return ret;
  }