Example usage for javafx.scene.media MediaView setPreserveRatio

List of usage examples for javafx.scene.media MediaView setPreserveRatio

Introduction

In this page you can find the example usage for javafx.scene.media MediaView setPreserveRatio.

Prototype

public final void setPreserveRatio(boolean value) 

Source Link

Document

Sets whether to preserve the media aspect ratio when scaling.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());
    final MediaPlayer mp = new MediaPlayer(m);
    final MediaView mv = new MediaView(mp);

    final DoubleProperty width = mv.fitWidthProperty();
    final DoubleProperty height = mv.fitHeightProperty();

    width.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
    height.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));

    mv.setPreserveRatio(true);

    StackPane root = new StackPane();
    root.getChildren().add(mv);// w w w.j a va2 s. c om

    final Scene scene = new Scene(root, 960, 540);
    scene.setFill(Color.BLACK);

    primaryStage.setScene(scene);
    primaryStage.setTitle("Full Screen Video Player");
    primaryStage.setFullScreen(true);
    primaryStage.show();

    mp.play();
}