美文网首页
Android 获取本地视频首帧及视频大小

Android 获取本地视频首帧及视频大小

作者: 带带我 | 来源:发表于2019-10-23 15:41 被阅读0次

    1、获取视频首帧

     MediaMetadataRetriever media = new MediaMetadataRetriever();
      //videoPath 视频路径
     media.setDataSource(videoPath);
      // 拿到 bitmap
     Bitmap bitmap = media.getFrameAtTime();
    
     imageCover.setImageBitmap(bitmap);
    

    2、获取视频大小

    //格式化
    public String getFormatSize(double size) {
            double kiloByte = size / 1024;
            if (kiloByte < 1) {
                return size + "B";
            }
    
            double megaByte = kiloByte / 1024;
            if (megaByte < 1) {
                BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
                return result1.setScale(2, BigDecimal.ROUND_HALF_UP)
                        .toPlainString() + "KB";
            }
    
            double gigaByte = megaByte / 1024;
            if (gigaByte < 1) {
                BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
                return result2.setScale(2, BigDecimal.ROUND_HALF_UP)
                        .toPlainString() + "MB";
            }
    
            double teraBytes = gigaByte / 1024;
            if (teraBytes < 1) {
                BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
                return result3.setScale(2, BigDecimal.ROUND_HALF_UP)
                        .toPlainString() + "GB";
            }
            BigDecimal result4 = new BigDecimal(teraBytes);
            return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
                    + "TB";
        }
    // file.length()  字节长度
    File file = new File(videoPath);
    String s = getFormatSize(file.length());
    

    相关文章

      网友评论

          本文标题:Android 获取本地视频首帧及视频大小

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