Adevelopment
Adevelopment

Reputation: 265

how to play multiple video one by one in VideoView in android

public class PlayMultipleVide extends Activity {

  VideoView videoView;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.multiplevideo);
    videoView=(VideoView) findViewById(R.id.videoview);
    MediaController mediaController= new MediaController(this);
    mediaController.setAnchorView(videoView);
    List<String> filedata=GetFiles("/storage/emulated/0/Android/data/com.example.android.camera2video/files");
    //specify the location of media file
    Uri uri=Uri.parse("/storage/emulated/0/Android/data/com.example.android.camera2video/files/"+filedata.get(0));
    //Setting MediaController and URI, then starting the videoView
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();
  }

  public static ArrayList<String> GetFiles(String DirectoryPath) {
    ArrayList<String> MyFiles = new ArrayList<>();
    File f = new File(DirectoryPath);
    f.mkdirs();
    File[] files = f.listFiles();
    if (files.length == 0)
      return null;
    else {
      for (File file : files) MyFiles.add(file.getName());
    }
    return MyFiles;
  }
}

This is my code. I have one folder file. Inside that, there are 5 videos, which I want to play one by one in VideoView whenever launched. I dont know how to play video one by one in videoview one at a time. Please suggest me .

Upvotes: 4

Views: 2985

Answers (1)

Sheikh
Sheikh

Reputation: 1146

Try to set listener to your videoView:

void setOnCompletionListener (MediaPlayer.OnCompletionListener l)

MediaPlayer.OnCompletionListener will tell you when the video reached EOS (end of stream). And then restart playback with new video Uri. Continue to do that until you have uris in list (List filedata).

Upvotes: 3

Related Questions