我尝试使用以下代码根据指定文件夹中存在的视频数量显示VideoView
。它不播放视频,只显示单个视频 View 。如有任何建议,请。
代码
File file=new File(Environment.getExternalStorageDirectory() + File.separator + "Funtube/UserData/Videos/" + File.separator);
File[] list = file.listFiles();
for (File f: list){
String name = f.getName();
if (name.endsWith(".mp4"))
count++;
for(int a=0;a<=count;a++)
{
VideoView vdos=(VideoView) findViewById(R.id.videoView);
String path=file.getAbsolutePath()+name;
vdos.setVideoURI(Uri.parse(path));
vdos.start();
}
最佳答案
public void onCreate()
{
link=new LinkedList<String>();
//declare linklist globally
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "Funtube/UserData/Videos/" + File.separator);
File[] list = file.listFiles();
for (File f : list) {
String name = f.getName();
if (name.endsWith(".mp4"))
String path = file.getAbsolutePath() + name;
//adding all Videos To List
link.add(path);
}
}
public void startvideo()
{
VideoView vdos=(VideoView) findViewById(R.id.videoView);
String path=link.get(0);
vdos.setVideoURI(Uri.parse(path));
vdos.start();
}
vv.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
String video=link.get(0);
link.remove(0);
link.add(video);
//this above code will put first video to last index of list
//by doing this we can play one video after another
startvideo();
}
});
您需要在Oncreate中初始化链表并添加oncomplet..监听器
关于java - 从指定的文件夹中播放 VideoView 中的视频数量 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432070/