?? ?? ?? ?? super.onCreate(savedInstanceState);
?? ?? ?? ?? setContentView(R.layout.activity_main);
?? ?? ?? ?? rv = (RecyclerView) findViewById(R.id.rv_local);
// ?? ?? ?? ??设置布局管理器
?? ?? ?? ?? LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
?? ?? ?? ?? rv.setLayoutManager(manager);
?? ?? ?? ?? mDatas = new ArrayList<>();
// ?? ?? ?? ??设置适配器对象
?? ?? ?? ?? adapter = new LocalVideoAdapter(this, mDatas);
?? ?? ?? ?? rv.setAdapter(adapter);
// ?? ?? ?? ??加载sd卡当中的视频,即真实的数据源
?? ?? ?? ?? loadData();
?? ?? }
?? ?? private void loadData() {
?? ?? ?? ?? List<LocalVideoInfo> list = new ArrayList<>();
// ?? ?? ?? ??1.获取ContentResolver对象
?? ?? ?? ?? ContentResolver resolver = getContentResolver();
// ?? ?? ?? ??2.获取Uri地址
?? ?? ?? ?? Uri videoUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
// ?? ?? ?? ??3.开始查询系统视频
?? ?? ?? ?? Cursor cursor = resolver.query(videoUri, null, null, null, MediaStore.Video.Media.DISPLAY_NAME);
// ?? ?? ??4.移动cursor指针

?? ?? ?? ?? while (cursor.moveToNext()) {
?? ?? ?? ?? ?? ?? String name = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
?? ?? ?? ?? ?? ?? String path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
?? ?? ?? ?? ?? ?? long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));
?? ?? ?? ?? ?? ?? long size = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.SIZE));
?? ?? ?? ?? ?? ?? LocalVideoInfo info = new LocalVideoInfo(name,path,duration,size);
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-54866-3.html
很喜欢舒淇