如何使JavaFX MediaView拉伸媒体填充父容器? [英] How do I make JavaFX MediaView stretch media to fill parent container?

查看:1060
本文介绍了如何使JavaFX MediaView拉伸媒体填充父容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的视频尺寸自动拉伸并填充MediaView并保持视频的原始宽高比。基本上,我希望我的MediaPlayer适合调整大小等父容器,就像几乎所有视频播放器一样。

I'm trying to make my video's dimensions stretch automatically and fill the MediaView and maintain the original aspect ratio of the video. Basically, I want my MediaPlayer to fit the parent container on resize etc. like pretty much all video players do.

如果有人能说明如何实现这一目标非常感谢,谢谢。

If anyone could shed some light on how to achieve this that would be much appreciated, thanks.

推荐答案

以下是拉伸到包含场景的示例,场景由Dimension设置尺寸:

Here's an example of stretching to the containing Scene and the scene is set by the Dimension "size":

final MediaPlayer videoPlayer = new MediaPlayer(
    new Media(new File(videoPath).toURI().toString()));
MediaView mv = new MediaView(videoPlayer);
DoubleProperty mvw = mv.fitWidthProperty();
DoubleProperty mvh = mv.fitHeightProperty();
mvw.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
mvh.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));
mv.setPreserveRatio(true);

setScene(new Scene(new Group(mv), size.getWidth(), size.getHeight()));

这篇关于如何使JavaFX MediaView拉伸媒体填充父容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆