我是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);
}
}
谢谢。