tabia
tabia

Reputation: 635

Play number of videos in VideoView from folder specified android

I have tried following code to display VideoView according to the number of videos present in specified folder. It isn't playing the videos and just show only single videoview. Any suggestions please.

Code

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

Upvotes: 0

Views: 1142

Answers (1)

koutuk
koutuk

Reputation: 832

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

you need to initilize LinkList in Oncreate also add oncomplet.. Listener

Upvotes: 1

Related Questions