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.
Just realized no-one answered this so I'll answer it.
Just set the media player fitWidthProperty to that of the MediaView so:
and the same for the height (if you wanted) and also preserveRatio and stuff.
Here's an example of stretching to the containing Scene and the scene is set by the Dimension "size":
A more declarative way in a ".fxml" file would be:
You can use the "${...}" syntax for any attribute in your ".fxml" for Expression Binding. If you want to call a UI element you have to provide a "fx:id". For example in this case it's fx:id="mediaViewPane".
So you don't have to care about the UI stuff in your code. For me it's a little bit cleaner.
I also struggled with this but I did this
and I worked for me. The
mediaView
played at the same size as the stage / window. Hope it helps.