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

标签 java android android-videoview

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

相关文章:

java - Lucene - 关键词归档困惑

android - Android 中双 SIM 卡设备的手机号码验证

android - 在Android中检测音频路径更改

带字幕的 Android 原生视频播放器

Android VideoView同时播放2个视频

android - 错误代码 (200,-82),Android 中的 MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK

java - 从 DER 格式的 String base64 编码创建 PrivateKey 和 PublicKey

java - Kerberos Java 凭据缓存

android - 带有 roboguice 抛出异常的简单 android 应用程序

java - 使用 Netbean 完成代码