Java Reference
In-Depth Information
smaller, there is not a large difference in quality between the smooth and nonsmooth options. Although the difference
in quality while upscaling is noticeable, it still may be acceptable for some applications. Therefore, if you need to
generate and show thumbnails of movies, this can be a worthwhile option to consider. By default,
smooth
is usually set
to true but this can depend on the platform on which you are running.
Listing 9-32 shows a full-screen movie player that uses the
fitWidth
,
fitHeight
, and
preserveRatio
to scale a
movie to play using the entire screen. This is accomplished by using the
Stage
's
fullScreen
property to ensure that
only the movie can be seen on the screen. Pressing the Escape key will restore the application to its normal window.
Listing 9-32.
A Full-Screen Movie Player
public class FullScreenVideoPlayer extends Application {
public static void main(String[] args) {
launch(args);
}
@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);
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();
}
}
The highlighted code in Listing 9-32 shows that
MediaView
's
fitWidth
and
fitHeight
properties are bound to the
width
and
height
properties of the
MediaView
's
Scene
object.
Bindings.selectDouble
is used to make sure
fitWidth
and
fitHeight
are updated when the
MediaView
is added to the active scene graph. For the movie to scale properly,
the
preserveRatio
property must be set to true.
Search WWH ::
Custom Search