TL;DR : Solution : Increase the JavaFX version to 15.0.1.
I am re-writing the question I asked yesterday because it was poorly formulated and poorly explained.
What I do : I use JavaFX to create a Media and a MediaView to render a .mp4 video in a scene.
What happens : The screen stays blank.
What should happen : The video should be rendered properly and visible by the user.
What I've tried :
- Changing the file encoding (from H.264 to QuickTime (outputs as .mov)).
- Result : QuickTime encoding isn't recognized by JavaFX.
- Changing the FPS value from 30 to 60 and from 60 to 30.
- Result : no difference.
- Tweaking the file size by shortening the video.
- Result : no difference.
- Changing the video resolution scale from 16:9 to 16:10.
- Result : no difference.
- Changing the video resolution value from 2560x1440 to 1920x1080.
- Result : the video is shown on the screen, but I need a 2560x1440 video to fill the screen. I will take care of different resolutions later on by myself.
- Using different videos from my computer.
- Result : resolutions less or equal to 1920x1080 are working fine. I tried video a different video with a 2560x1440 resolution and it does not work.
- Using a 2560x1440 video referenced by an internet URL.
- Result : same behavior as described above.
My code :
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import java.io.File;
public class Application extends javafx.application.Application {
Stage window;
@Override
public void start(Stage primaryStage) {
window = primaryStage;
window.setWidth(2560);
window.setHeight(1440);
window.setX(0);
window.setY(0);
window.setResizable(false);
window.setFullScreen(true);
window.setFullScreenExitHint("");
Pane pane = new Pane();
// Example to show that adding a simple figure to the pane works fine.
javafx.scene.shape.Rectangle r = new javafx.scene.shape.Rectangle(0, 0, 150, 150);
Media media = new Media(new File(/*Insert file name you own for testing purposes*/).toURI().toString());
// The path I would use : "src\\main\\resources\\img\\Animated Titlescreen Background.mp4".
// This is obtained using other classes and methods that read the computer directories,
// so it works fine across different computers.
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
MediaView mediaView = new MediaView(mediaPlayer);
pane.getChildren().addAll(mediaView, r);
Scene scene = new Scene(pane, 2560, 1440);
window.setScene(scene);
window.show();
}
public static void main(String[] args) {
launch(args);
}
}