简体   繁体   English

JavaFX MediaView 呈现白色视频

[英]JavaFX MediaView rendering a white video

TL;DR : Solution : Increase the JavaFX version to 15.0.1. TL;DR:解决方案:将 JavaFX 版本增加到 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.我的工作:我使用 JavaFX 创建一个 Media 和一个 MediaView 在场景中渲染 .mp4 视频。

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)).更改文件编码(从 H.264 到 QuickTime(输出为 .mov))。
    • Result : QuickTime encoding isn't recognized by JavaFX.结果:JavaFX 无法识别 QuickTime 编码。
  • Changing the FPS value from 30 to 60 and from 60 to 30.将 FPS 值从 30 更改为 60 和从 60 更改为 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.将视频分辨率比例从 16:9 更改为 16:10。
    • Result : no difference.结果:没有区别。
  • Changing the video resolution value from 2560x1440 to 1920x1080.将视频分辨率值从 2560x1440 更改为 1920x1080。
    • Result : the video is shown on the screen, but I need a 2560x1440 video to fill the screen.结果:视频显示在屏幕上,但我需要一个 2560x1440 的视频来填满屏幕。 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.结果:小于或等于 1920x1080 的分辨率工作正常。 I tried video a different video with a 2560x1440 resolution and it does not work.我尝试使用 2560x1440 分辨率录制不同的视频,但它不起作用。
  • Using a 2560x1440 video referenced by an internet URL.使用 Internet URL 引用的 2560x1440 视频。
    • 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);
    }
}

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.此链接上阅读更多内容后,它说Windows 8 将 H.264 解码器分辨率提高到 4096x2304 ,可在 JavaFX 版本 15.0.1 上使用。 I was using version 12.0.1 because of a critical issue on Linux with version 15.0.1.我使用的是 12.0.1 版本,因为 Linux 版本 15.0.1 上存在一个严重问题。

Solution : Increase the JavaFX version to 15.0.1.解决方案:将 JavaFX 版本增加到 15.0.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM