JavaFX-看不到视频MediaView

时间:2018-11-27 00:00:51

标签: java javafx video-streaming javafx-8

我是JavaFX的新手,在学习期间,我一直无法显示视频,却无法观看,但是令人印象深刻的是音频一直在播放。

这是我的代码:

public class ExemploJavafx extends Application {

    StackPane root;
    Media theMedia;
    MediaPlayer thePlayer;
    MediaView theView;

    @Override
    public void start(Stage primaryStage) {

        root = new StackPane();
        try {
            theMedia = new Media(new File("D:\\Download \\de.flv").toURI().toString());
            thePlayer = new MediaPlayer(theMedia);
            thePlayer.setAutoPlay(true);

            theView = new MediaView();
            theView.setFitHeight(100);
            theView.setFitWidth(100);

            theView.setMediaPlayer(thePlayer);
        } catch (Exception e) {
            e.printStackTrace();
        }

        root.getChildren().addAll(theView);

        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Media View");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }

}

谢谢。

0 个答案:

没有答案