标签:os io java ar 数据 代码 sp on c
首先自己写一个视频实体类,代码如下:
public class VideoEntity { public int ID;//ID public String title;//标题 public String filePath;//绝对路径 public int size;//大小 public int duration;//时长 }
再查询本地数据库,根据传入相应字段,获取数据,代码如下:
private void getVideoFile(){ ContentResolver mContentResolver = getContentResolver(); Cursor cursor = mContentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.DEFAULT_SORT_ORDER); if (cursor.moveToFirst()) { do { // ID:MediaStore.Audio.Media._ID int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); // 名称:MediaStore.Audio.Media.TITLE String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE)); // 路径:MediaStore.Audio.Media.DATA String url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); // 总播放时长:MediaStore.Audio.Media.DURATION int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); // 大小:MediaStore.Audio.Media.SIZE int size = (int) cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)); VideoEntity entty = new VideoEntity(); entty.ID = id; entty.title = title; entty.filePath = url; entty.duration = duration; entty.size = size; //mList.add(entty); } while (cursor.moveToNext()); } if (cursor != null) { cursor.close(); cursor = null; } }
标签:os io java ar 数据 代码 sp on c
原文地址:http://my.oschina.net/oppo4545/blog/309277