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

Asked

Viewed 134 times

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 follow 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 good, 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 run the next method, you need to manually close the video.

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

1 answer

0

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

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

            }
        }
    }); 
  • Dude, seriously, seriously, thank you so much. Just to perfect the answer, inside the run I put the "stage.close();" to close the video and then I turned around as I could, but it really helped me, really

Browser other questions tagged

You are not signed in. Login or sign up in order to post.