0

Okay so i have this method that should run a video, wait till it ends, then play a second video.

My problem is that the program doesn't seem to wait for the first video to end, and therefore directly jumped to the second video.

I the added the wait() method, and it causes the first video to play, but then it stops and the second video never starts.

Any help would be much appreciated!

  private void test(ActionEvent event) throws InterruptedException {

        File fi= new File("test\\firstVideo.mp4");

        String filePath= fi.toURI().toString();

        openFile(filePath);

        wait(5000); //even wait(0) has the same effect

        fi= new File("test\\secondVideo.mp4");

        filePath= fi.toURI().toString();

        openFile(filePath);
    }

2 Answers2

1

I think you're confusing wait() and sleep() (Difference between wait() and sleep())

IN your case, you might want to listen to some file/video event and handle it there.

ricardofagodoy
  • 146
  • 1
  • 10
  • well i tried sleep, it makes the program wait the amount of time set, then it plays the second video only :S can you explain more the video listening part? – Jeremy Lucas Jun 02 '17 at 17:16
  • Can you give me more detail of your `openFile` function? – ricardofagodoy Jun 02 '17 at 17:18
  • `private void openFile(String filePath){ if (filePath != null) { Media media = new Media(filePath); mediaPlayer = new MediaPlayer(media); mediaView.setMediaPlayer(mediaPlayer); DoubleProperty width = mediaView.fitWidthProperty(); DoubleProperty height = mediaView.fitHeightProperty(); width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height")); mediaPlayer.play(); } }` – Jeremy Lucas Jun 02 '17 at 17:24
  • Check it out: https://stackoverflow.com/questions/37812067/callback-from-mediaplayer – ricardofagodoy Jun 02 '17 at 17:26
0

Can you get the videos length? Because Java is able to read the meta data of some files... You can try to use a timer instead to wait for the video to finish. Maybe you can get the length of the video and set a timer to call the same function (recursion) with a different parameter and play the other video. So basically make the function take the path as parameter, and play the video of that parameter. If you don't know already, Java has a Timer class where a timer instance takes an amount of seconds and a function to call in its constructor, and it has a .play() method.

user7437896
  • 68
  • 1
  • 5
  • 11