今天記錄一下獲取本地視頻時長的方法
/** * 獲取本地視頻的時長 * * @param Videopath * @return */ public static long getPathLoang(String Videopath) { long time = 0; MediaPlayer meidaPlayer = new MediaPlayer(); try { meidaPlayer.setDataSource(Videopath); meidaPlayer.prepare(); time = meidaPlayer.getDuration() / 1000; } catch (IOException e) { e.printStackTrace(); } return time; }
獲取視頻第一楨圖片
/** * 獲取視頻的第一幀 * * @param path * @return */ public static Bitmap getVideoThumb(String path) { MediaMetadataRetriever media = new MediaMetadataRetriever(); media.setDataSource(path); return media.getFrameAtTime(); }
獲取本地圖片的大小
public static String bytes2kb(long bytes){ BigDecimal fileSize = new BigDecimal(bytes); BigDecimal megabyte = new BigDecimal(1024*1024); float returnFloat = fileSize.divide(megabyte, 2, BigDecimal.ROUND_UP).floatValue(); if (returnFloat>1){ return returnFloat+"MB"; } BigDecimal kilobyte = new BigDecimal(1024); returnFloat=fileSize.divide(kilobyte,2,BigDecimal.ROUND_UP).floatValue(); return returnFloat+"kb"; }
public String pathSize(String imgUrl){ File file = new File(imgUrl); FileInputStream fis; long fileLen = 0; try { fis = new FileInputStream(file); fileLen=fis.available(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.e("長度","s"+BitmapUtil.bytes2kb(fileLen)); }