2015-12-23 51 views
0

我试过以下代码,根据指定文件夹中存在的视频数量来显示VideoView。它不播放视频,只显示单个视频视图。任何建议请。从指定文件夹中播放VideoView中的视频数android

代码

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(); 
     } 
+0

使用VideoView' ?正如我在我的活动中展示了单个'VideoView'。我想在不同'VideoViews'中显示所有视频 – koutuk

+0

但如何增加' – tabia

回答

1
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 .. 监听

上完成听者比播放下一部
+0

此代码是否会在我的活动文件中增加数量的VideoView? – tabia

+0

看到代码写在OncompletionListener – koutuk

+0

它将删除第一个索引元素并放到最后......现在我们有第二个顶部.... – koutuk