예제 #1
0
 /** 是否正在运行 */
 public static boolean isRunning() {
   ActivityManager manager =
       (ActivityManager)
           OPlayerApplication.getContext().getSystemService(Context.ACTIVITY_SERVICE);
   for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
     if (SERVICE_NAME.equals(service.service.getClassName())) return true;
   }
   return false;
 }
예제 #2
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();
    }
  }