Java Reference
In-Depth Information
The MediaView class is a subclass of Node that provides a view of the Media being played
by a MediaPlayer . The MediaView class provides the properties for viewing the media, as
shown in FigureĀ 16.32.
The getter and setter methods for property
values and a getter for property itself are provided
in the class, but omitted in the UML diagram for brevity.
javafx.scene.media.MediaView
-x: DoubleProperty
-y: DoubleProperty
-mediaPlayer:
ObjectProperty<MediaPlayer>
-fitWidth: DoubleProperty
-fitHeight: DoubleProperty
Specifies the current x-coordinate of the media view.
Specifies the current y-coordinate of the media view.
Specifies a media player for the media view.
Specifies the width of the view for the media to fit.
Specifies the height of the view for the media to fit.
+MediaView()
+MediaView(mediaPlayer: MediaPlayer)
Creates an empty media view.
Creates a media view with the specified media player.
F IGURE 16.32
MediaView provides the properties for viewing the media.
Listing 16.14 gives an example that displays a video in a view, as shown in FigureĀ 16.33. You
can use the play/pause button to play or pause the video and use the rewind button to restart
the video, and use the slider to control the volume of the audio.
F IGURE 16.33
The program controls and plays a video.
L ISTING 16.14
MediaDemo.java
1 import javafx.application.Application;
2 import javafx.stage.Stage;
3 import javafx.geometry.Pos;
4 import javafx.scene.Scene;
5 import javafx.scene.control.Button;
6 import javafx.scene.control.Label;
7 import javafx.scene.control.Slider;
8 import javafx.scene.layout.BorderPane;
9 import javafx.scene.layout.HBox;
10 import javafx.scene.layout.Region;
11 import javafx.scene.media.Media;
 
 
Search WWH ::




Custom Search