获取视频列表
/**
- 获取本机视频列表
- @return
*/
public List getVideos() {
List videos = new ArrayList();
Cursor c = null;
try {
// String[] mediaColumns = { “_id”, “_data”, “_display_name”,
// “_size”, “date_modified”, “duration”, “resolution” };
c = mContentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER);
while (c.moveToNext()) {
String path = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));// 路径
if (!FileUtils.isExists(path)) {
continue;
}
int id = c.getInt(c.getColumnIndexOrThrow(MediaStore.Video.Media._ID));// 视频的id
String name = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)); // 视频名称
String resolution = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION)); //分辨率
long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));// 大小
long duration = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));// 时长
long date = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_MODIFIED));//修改时间
Video video = new Video(id, path, name, resolution, size, date, duration);
videos.add(video);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (c != null) {
c.close();
}
}
return videos;
}
其中,视频的bean类Video代码为:
public class Video {
private int id = 0;
private String path = null;
private String name = null;
private String resolution = null;// 分辨率
private long size = 0;
private long date = 0;
private long duration = 0;
public Video(int id, String path, String name, String resolution, long size, long date, long duration) {
this.id = id;
this.path = path;
this.name = name;
this.resolution = resolution;
this.size = size;
this.date = date;
this.duration = duration;
}
… //此处省略setter和getter方法
&