@modesta
To play a video in JavaFX on Linux, you can follow these steps:
- Make sure you have Java Development Kit (JDK) installed on your Linux machine.
- Download and extract the JavaFX SDK, which includes the necessary libraries for working with media.
- Set up the JavaFX environment variables by adding the following lines to your bashrc or bash_profile file:
export PATH_TO_FX=/path/to/javafx-sdk-X.X.X/lib
export PATH=$PATH:$PATH_TO_FX
export CLASSPATH=$PATH_TO_FX/jfxrt.jar:$CLASSPATH
- Compile and run the JavaFX program using the javac and java commands. Here's a simple example that plays a video file:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
public class VideoPlayer extends Application {
@Override
public void start(Stage primaryStage) {
String videoPath = "file:///path/to/video.mp4";
Media media = new Media(videoPath);
MediaPlayer mediaPlayer = new MediaPlayer(media);
MediaView mediaView = new MediaView(mediaPlayer);
primaryStage.setScene(new Scene(mediaView, 800, 600));
primaryStage.show();
mediaPlayer.play();
}
public static void main(String[] args) {
launch(args);
}
}
Replace /path/to/video.mp4 with the actual path to your video file.
- Compile the JavaFX program using the following command:
javac --module-path $PATH_TO_FX --add-modules javafx.controls,javafx.media VideoPlayer.java
- Run the JavaFX program using the following command:
java --module-path $PATH_TO_FX --add-modules javafx.controls,javafx.media VideoPlayer
This will launch a window with the video playing in it.
Make sure you have the necessary codecs installed on your Linux machine to play the video file.