How do I automatically perform an action at the end of a video?

1

Follow the video code

package video;

import javafx.application.Application;

import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

public class Entrada2_Video extends Application {

    public String VIDEO_URL = getClass().getResource("/conteudos/Video_Final3.mp4").toString();

    public static void rodarVideo() {
        launch();
        Entrada1.texto();
    }

    public void start(Stage palco) throws Exception {

        Media media = new Media(VIDEO_URL);
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        MediaView mediaView = new MediaView(mediaPlayer);

        mediaPlayer.play();

        StackPane raiz = new StackPane();
        raiz.getChildren().add(mediaView);
        Scene cena = new Scene(raiz, 854, 480);
        palco.setTitle("Peão Genio Quiz");
        palco.sceneProperty();
        palco.setScene(cena);
        palco.show();
        palco.setResizable(false);


        mediaPlayer.play();
    }

}

There is nothing different from other codes already seen on the internet. Now follows the Main class, where all methods will be executed.

package video;

public class Principal{

    public static void main(String[] args)  {

        Entrada2_Video.rodarVideo();

    }

}

The program runs fine, the big problem is that I do not know how to close the video automatically at the end of the execution of it! That is, if I want to execute the next method, you must manually close the video.

I would just like to know how to close the video automatically after the end of the video, so that the next method will be executed after the video is closed.

    
asked by anonymous 18.11.2018 / 23:40

1 answer

0

Hello, if I understood correctly at the end of the execution of a media you want to perform an action .. for this purpose use this method .. put your action inside run ()

    mediaPlayer.setOnEndOfMedia(new Runnable() {
        public void run() {

            }
        }
    }); 
    
21.11.2018 / 16:22