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);
- if (context != null) {
- Cursor cursor = context.getContentResolver().query(
- MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null,
- null, null);
- if (cursor != null) {
- list = new ArrayList<Video>();
- while (cursor.moveToNext()) {
- int id = cursor.getInt(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media._ID));
- String title = cursor
- .getString(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
- String album = cursor
- .getString(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.ALBUM));
- String artist = cursor
- .getString(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST));
- String displayName = cursor
- .getString(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME));
- String mimeType = cursor
- .getString(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
- String path = cursor
- .getString(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
- long duration = cursor
- .getInt(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
- long size = cursor
- .getLong(cursor
- .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
- Video video = new Video(id, title, album, artist, displayName, mimeType, path, size, duration);
- list.add(video);
- }
- cursor.close();
- }
- }
- http://blog.csdn.net/jwzhangjie/article/details/9027607
|