在列表视图中显示 sdcard 文件夹中的视频文件
我正在尝试在 SD 卡上的文件夹“abc”的列表视图中显示视频文件,我已成功显示,但问题是它显示存储在 SD 卡上的所有视频文件,甚至在文件夹“abc”之外,实际上我只想存储在文件夹“中的视频文件” abc' 显示。我已经用谷歌搜索了很多天,但没有找到任何解决方案。我的代码是:
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;
}
有提示吗?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,请勿使用内容提供程序。内容提供商将为您提供其可以在您的设备上找到的所有视频的信息。
编写您自己的小实用程序来扫描并拾取您需要的文件/文件夹。
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.
为托管查询提供筛选条件,以筛选您的文件夹名称。
查看该方法的 javadoc。它具有选择记录的标准。这应该允许您选择所需的子集。
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.
不要使用以下代码:
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
使用以下代码编辑此代码:
videocursor = MainActivity.this. ManagedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,null, MediaStore.Images.Media.DATA + " like ? ",new String[] {"%abc%"} ,无效的);
这肯定会对您有所帮助......
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.......