Пример #1
0
  /** 提取生成缩略图 */
  @SuppressWarnings("unused")
  private void extractThumbnail(POMedia media) {
    final Context ctx = OPlayerApplication.getContext();
    //		ThumbnailUtils.
    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(ctx, media.path, ThumbnailUtils.MINI_KIND);
    try {
      if (bitmap == null) {
        // 缩略图创建失败
        bitmap =
            Bitmap.createBitmap(
                ThumbnailUtils.TARGET_SIZE_MINI_THUMBNAIL_WIDTH,
                ThumbnailUtils.TARGET_SIZE_MINI_THUMBNAIL_HEIGHT,
                Bitmap.Config.RGB_565);
      }

      media.width = bitmap.getWidth();
      media.height = bitmap.getHeight();

      // 缩略图
      bitmap =
          ThumbnailUtils.extractThumbnail(
              bitmap,
              ConvertUtils.dipToPX(ctx, ThumbnailUtils.TARGET_SIZE_MICRO_THUMBNAIL_WIDTH),
              ConvertUtils.dipToPX(ctx, ThumbnailUtils.TARGET_SIZE_MICRO_THUMBNAIL_HEIGHT),
              ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
      if (bitmap != null) {
        // 将缩略图存到视频当前路径
        File thum = new File(OPlayerApplication.OPLAYER_VIDEO_THUMB, UUID.randomUUID().toString());
        media.thumb_path = thum.getAbsolutePath();
        // thum.createNewFile();
        FileOutputStream iStream = new FileOutputStream(thum);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 85, iStream);
        iStream.close();
      }

      // 入库

    } catch (Exception ex) {
      Logger.e(ex);
    } finally {
      if (bitmap != null) bitmap.recycle();
    }
  }
Пример #2
0
  /**
   * 保存入库
   *
   * @throws FileNotFoundException
   */
  private void save(POMedia media) {
    mDbWhere.put("path", media.path);
    mDbWhere.put("last_modify_time", media.last_modify_time);
    // 检测
    if (!mDbHelper.exists(media, mDbWhere)) {
      try {
        if (media.title != null && media.title.length() > 0)
          media.title_key = PinyinUtils.chineneToSpell(media.title.charAt(0) + "");
      } catch (Exception ex) {
        Logger.e(ex);
      }
      media.last_access_time = System.currentTimeMillis();

      // 提取缩略图
      //			extractThumbnail(media);
      media.mime_type = FileUtils.getMimeType(media.path);

      // 入库
      mDbHelper.create(media);

      // 扫描到一个
      notifyObservers(SCAN_STATUS_RUNNING, media);
    }
  }