0

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);
    }
}
Nephty
  • 140
  • 1
  • 7
  • 2
    Seems like the media implementation has trouble with videos above a certain resolution. Are you using the latest version of JavaFX? If not, can you try with the latest? What operating system are you testing on? Can you provide the MP4 video file? – Slaw Jul 02 '21 at 10:41
  • Side note: If your MP4 video is a _resource_ then you should be accessing it as such (e.g. `getClass().getResource("/img/Animated Titlescreen Background.mp4")`) instead of a file. Resources are not files and your approach is likely to break upon deployment. – Slaw Jul 02 '21 at 10:43
  • 1
    Possibly related Q&A (for 4K video): https://stackoverflow.com/questions/26160709/javafx-ultra-hd-4k-video. Possibly related bug report (also for 4K video): https://bugs.openjdk.java.net/browse/JDK-8091277 (this duplicate says JavaFX can't play above 1920x1080: https://bugs.openjdk.java.net/browse/JDK-8208188). – Slaw Jul 02 '21 at 10:50
  • don't repost - instead improve the previous by editing/adding clarifications as needed – kleopatra Jul 02 '21 at 11:17
  • Hello @Slaw ! The file is available at [this](https://github.com/Nephty/Star-Defender-Java/tree/main/src/main/resources/img) link (GitHub). I am using a File instead of a Resource, but someone else also pointed this out. I will take a look at that, but it's not a priority at the moment. On one of the bug reports, it seems that _Windows 8 increase H.264 decoder resolution to 4096x2304_, which I would assume is now available ? I used JavaFX 12.0.1 because the 15.0.1 version had a known critical issue with Linux, where the program would simply not run. – Nephty Jul 02 '21 at 12:17
  • After testing, it turns out JavaFX version must be 15.0.1 in order to play higher resolution videos than FHD. Thank you for the useful links. – Nephty Jul 02 '21 at 12:18
  • (@kleopatra first issue was removed) – Nephty Jul 02 '21 at 12:18
  • "_I am using a File instead of a Resource_" – Everything under `src/main/resources` is a resource. From the project's source perspective they are files. But conceptually resources are not files and treating them as such is wrong. The resource API (e.g. `getResource`) is designed to load things from the class-path/module-path independent of the application's location. When you deploy your application the `src/main/resources` directory no longer exists. Also, the resource typically—and literally—stops being a file upon deployment and instead is e.g. an entry in a JAR file. – Slaw Jul 03 '21 at 00:08
  • Even pre-deployment, there's still a problem running your application via the IDE or build tool. When you build your project the IDE/build tool typically copies/processes resources and places the copy in the appropriate output location. Your code ignores this and instead uses the original copy of the resource under the source location. It happens to work for you because usually the working directory ends up being the project directory when executing the project directly. – Slaw Jul 03 '21 at 00:18
  • Thank you very much for the help. Will proceed to change to Resources. – Nephty Jul 03 '21 at 10:58
  • If you run into issues loading resources in JavaFX then check out this Q&A: [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/questions/61531317/). – Slaw Jul 03 '21 at 23:21

1 Answers1

1

After reading more on this link, it says Windows 8 increase H.264 decoder resolution to 4096x2304, which is available on JavaFX version 15.0.1. I was using version 12.0.1 because of a critical issue on Linux with version 15.0.1.

Solution : Increase the JavaFX version to 15.0.1.

Nephty
  • 140
  • 1
  • 7
  • Note the latest version of JavaFX is 16. Perhaps your "critical issue on Linux" has been fixed as well. – Slaw Jul 02 '21 at 23:58
  • Thank you for the hint. I will try to re-run on Linux and see if the issue has been fixed. FYI the issue was called "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT" – Nephty Jul 03 '21 at 10:57