I have the below code to play a video using MediaView
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
public class PlayVideo extends Application {
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
MediaPlayer player = new MediaPlayer( new Media(getClass().getResource("Demo.mp4").toExternalForm()));
MediaView mediaView = new MediaView(player);
DoubleProperty mvw = mediaView.fitWidthProperty();
DoubleProperty mvh = mediaView.fitHeightProperty();
mvw.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
mvh.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
mediaView.setPreserveRatio(true);
mediaView.setSmooth(true);
root.getChildren().add( mediaView);
Scene scene = new Scene(root, 1024, 768);
primaryStage.setScene(scene);
primaryStage.show();
player.play();
}
public static void main(String[] args) {
launch(args);
}
}
The video plays fine and all looks good. But when i resize the video to a smaller size (Resize the stage) the video lost clarity and everything is distorted.
Following is my video details:
Is it possible to retain the clarity on resize to smaller size. Other media players like Windows media player or VLC retains the clarity on resize.
How can i achieve this?