gpt4 book ai didi

java - 从指定的文件夹中播放 VideoView 中的视频数量 android

转载 作者:行者123 更新时间:2023-12-01 10:40:41 25 4
gpt4 key购买 nike

我尝试使用以下代码根据指定文件夹中存在的视频数量显示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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com