Display video files in listview from sdcard folder

末鹿安然 提交于 2019-12-10 21:35:13

问题


I am trying to display video files in listview from folder 'abc' on sdcard, i have successfully displayed but problem is that it displays all video files stored on sdcard even out of folder 'abc' actually i want only video files stored in folder 'abc' to be displayed. I am googling since more days but didn't find any solution for that. My code is:

videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
count = videocursor.getCount();
videolist = (ListView) findViewById(R.id.listview);
videolist.setAdapter(new VideoAdapter(getApplicationContext()));
videolist.setOnItemClickListener(videogridlistener);
}
private OnItemClickListener videogridlistener = new OnItemClickListener() {
public void onItemClick(AdapterView<?>parent, View v, int position,
long id) {
System.gc();
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videocursor.moveToPosition(position);
String filename = videocursor.getString(video_column_index);
Intent intent = new Intent(VideoActivity.this, ViewVideo.class);
intent.putExtra("videofilename", filename);
startActivity(intent);
}
};

public class VideoAdapter extends BaseAdapter {
private Context vContext;
public VideoAdapter(Context c) {
vContext = c;
}

public int getCount() {
return count;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
TextView tv = new TextView(vContext.getApplicationContext());
String id = null;
if (convertView == null) {
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE);
videocursor.moveToPosition(position);
id = videocursor.getString(video_column_index);
tv.setText(id);
} 
else
{
tv = (TextView) convertView;
return tv;
}

Any Hint? Thanks in advance.


回答1:


Don't use the content provider in this case. The content provider will give you info on all the videos that it can find on your device.

Write your own little utility to scan and pick up the files/folders that you require.




回答2:


Provide a filtering criteria to the managed query that filters for your folder name.

Look at the javadoc for the method. It has criteria for the selection of records. That should allow you to select your desired subset.




回答3:


Dont Use This following code:

video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);

Edit This code with the following code:

videocursor = MainActivity.this.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,null, MediaStore.Images.Media.DATA + " like ? ",new String[] {"%abc%"},null);

THIS WILL HELP YOU FOR SURE.......



来源:https://stackoverflow.com/questions/7733983/display-video-files-in-listview-from-sdcard-folder

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