display videos from specific folder from sd card in listview

南笙酒味 提交于 2019-12-11 07:36:48

问题


i am trying to populate listview with video files from a folder created on sd card. I am using

managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,mystring, null, null, null);

But it populates all videos saved in sdcard, but i want only those videos which are saved in specific folder. I have also used

Uri uri = Uri.fromFile(filepath);
cursor = managedQuery(uri, mystring , null , null , null); 

and

Uri uri = Uri.parse(filepath);
cursor = managedQuery(uri, mystring , null , null , null);

But it doesn't work. I have tried lot and got help from google still not succeded. Is there any way to give path of that folder? or any other way?


回答1:


you can use this code for get videos from specific folder as:

String selection=MediaStore.Video.Media.DATA +" like?";
        String[] selectionArgs=new String[]{"%FolderName%"};
        videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                parameters, selection, selectionArgs, MediaStore.Video.Media.DATE_TAKEN + " DESC");



回答2:


You can get a files form a specific location like this

item = new ArrayList<String>();
 path = new ArrayList<String>();

 File f = new File("/sdcard/");

 // or you can use File f=new File(Environment.getExternalStorageDirectory().getPAth());
 File[] files = f.listFiles();


 for(int i=0; i < files.length; i++)
 {
   File file = files[i];
   path.add(file.getPath());
   if(file.isDirectory())
    item.add(file.getName() + "/");
   else
    item.add(file.getName());
 }

 ArrayAdapter<String> fileList =
  new ArrayAdapter<String>(this, R.layout.row, item);
 setListAdapter(fileList);



回答3:


hey managedquery search the whole sdcard not the specific folder . the above method is true of display the name of file but if you to display thumbnail create thumbmail and store in in Hashmap and populate it to the list of gallery adapter..........



来源:https://stackoverflow.com/questions/7786721/display-videos-from-specific-folder-from-sd-card-in-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!