joy_chen / video&audio / 获取多媒体文件信息

分享

   

获取多媒体文件信息

2014-04-12  joy_chen
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource(/* file descriptor or file path goes here */);
String height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
  1. if (context != null) {  
  2.             Cursor cursor = context.getContentResolver().query(  
  3.                     MediaStore.Video.Media.EXTERNAL_CONTENT_URI, nullnull,  
  4.                     nullnull);  
  5.             if (cursor != null) {  
  6.                 list = new ArrayList<Video>();  
  7.                 while (cursor.moveToNext()) {  
  8.                     int id = cursor.getInt(cursor  
  9.                             .getColumnIndexOrThrow(MediaStore.Video.Media._ID));  
  10.                     String title = cursor  
  11.                             .getString(cursor  
  12.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));  
  13.                     String album = cursor  
  14.                             .getString(cursor  
  15.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.ALBUM));  
  16.                     String artist = cursor  
  17.                             .getString(cursor  
  18.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST));  
  19.                     String displayName = cursor  
  20.                             .getString(cursor  
  21.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME));  
  22.                     String mimeType = cursor  
  23.                             .getString(cursor  
  24.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));  
  25.                     String path = cursor  
  26.                             .getString(cursor  
  27.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.DATA));  
  28.                     long duration = cursor  
  29.                             .getInt(cursor  
  30.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));  
  31.                     long size = cursor  
  32.                             .getLong(cursor  
  33.                                     .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));  
  34.                     Video video = new Video(id, title, album, artist, displayName, mimeType, path, size, duration);  
  35.                     list.add(video);  
  36.                 }  
  37.                 cursor.close();  
  38.             }  
  39.         }  
  40. http://blog.csdn.net/jwzhangjie/article/details/9027607

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>