如何在Android活动中显示特定文件夹中的视频?

时间:2017-03-08 05:18:54

标签: android android-videoview

我想在Android活动中显示特定文件夹中的所有视频。因此,当用户点击它时,视频将在Android内部视频播放器等播放。请帮助我完成我的任务。我也发布了我想要的输出图片。我想要列表视频,就像在图片中一样。this is picture of MX-player, i want same functionality in my application

1 个答案:

答案 0 :(得分:0)

尝试下面给出的代码:

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;
}

如果您遇到任何问题,请告诉我,我们很乐意为您提供帮助。