1、获取本地所有视频
public void getLoadMedia() { Cursor cursor = UILApplication.instance.getApplicationContext().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER); try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); // id String displayName =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 title = 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)); // 大小 String resolution =cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION)); } } catch (Exception e) { e.printStackTrace(); } finally { cursor.close(); } }
2、获取拍照视频
public static final String[] videoCursorCols = new String[] { MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.TITLE, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.ARTIST, MediaStore.Video.Media.ALBUM, MediaStore.Video.Media.RESOLUTION, MediaStore.Video.Media.MIME_TYPE, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DATA }; public static Video fileUriForVideo(Activity activity, Uri uri) { Cursor cursor = activity.getContentResolver().query(uri, videoCursorCols, null, null, null); if (cursor == null || cursor.getCount() == 0) { return null; } else { Video video = new Video(); cursor.moveToFirst(); /* file name */ if (cursor.getString(1) != null) { video.setName(cursor.getString(1)); } /* media name */ if (cursor.getString(2) != null) { video.setDisplayName(cursor.getString(2)); } /* play duration */ if (cursor.getString(3) != null) { video.setTimelong((cursor.getInt(3) / 1000) + "s"); } /* artist */ if (cursor.getString(4) != null) { video.setSinger(cursor.getString(4)); } /* album */ if (cursor.getString(5) != null) { video.setAlbum(cursor.getString(5)); } /* resolution */ if (cursor.getString(6) != null) { video.setResolution(cursor.getString(6)); } /* media type */ if (cursor.getString(7) != null) { video.setMimeType(cursor.getString(7).trim()); } /* media size */ if (cursor.getString(8) != null) { video.setDownfilesize(new java.text.DecimalFormat("#.00").format((cursor.getInt(8) / 1024.0 / 1024.0)) + " MB"); } /* media file path */ if (cursor.getString(9) != null) { video.setVoiceurl(cursor.getString(9)); } if (cursor != null) { cursor.close(); } return video; } }
时间: 2024-10-07 03:22:28