Node that provides a view of Media being played by a
MediaPlayer.
The following code snippet provides a simple example of an
Application.
method which displays a video:
public void start(Stage stage) {
// Create and set the Scene.
Scene scene = new Scene(new Group(), 540, 209);
stage.setScene(scene);
// Name and display the Stage.
stage.setTitle("Hello Media");
stage.show();
// Create the media source.
String source = getParameters().getRaw().get(0);
Media media = new Media(source);
// Create the player and set to play automatically.
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
// Create the view and add it to the Scene.
MediaView mediaView = new MediaView(mediaPlayer);
((Group) scene.getRoot()).getChildren().add(mediaView);
}
The foregoing code will display the video as:
| Modifier and Type | Class and Description |
|---|---|
| private class | MediaView.
Inner class used to convert a |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private VideoFrameRateListener | decodedFrameRateListener
Listener for decoded frame rate. |
| private static final String | |
| private InvalidationListener | errorListener
Listener which converts |
| private DoubleProperty | fitHeight
Determines the height of the bounding box within which the source media is resized as necessary to fit. |
| private DoubleProperty | fitWidth
Determines the width of the bounding box within which the source media is resized as necessary to fit. |
| private InvalidationListener | mediaDimensionListener
Listener which causes the geometry to be updated when the media dimension changes. |
| private ObjectProperty | mediaPlayer
The |
| private MediaPlayerOverlay | |
| private ObjectProperty | onError
Event handler to be invoked whenever an error occurs on this
|
| private ChangeListener | |
| private ChangeListener | |
| private BooleanProperty | preserveRatio
Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the node. |
| private boolean | |
| private int | |
| private BooleanProperty | smooth
If set to |
| private ChangeListener | |
| private static final String | VIDEO_FRAME_RATE_PROPERTY_NAME
The name of the property in the |
| private ObjectProperty | viewport
Specifies a rectangular viewport into the media frame. |
| private DoubleProperty | x
Defines the current x coordinate of the |
| private DoubleProperty | y
Defines the current y coordinate of the |
| Access | Constructor and Description |
|---|---|
| public | |
| public | MediaView(MediaPlayer
the mediaPlayer)MediaPlayer the playback of which is to be
viewed via this class.Creates a |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| private static Affine3D | |
| private void | |
| private VideoFrameRateListener | |
| private boolean | |
| private boolean | |
| private BaseBounds | |
| private NGNode | |
| private void | |
| private void | |
| public final DoubleProperty | |
| public final DoubleProperty | |
| public final double | Returns: the height of the resized media.Retrieves the height of the bounding box of the resized media. |
| public final double | Returns: the height of the resized media.Retrieves the width of the bounding box of the resized media. |
| public final MediaPlayer | Returns: the associatedMediaPlayer.Retrieves the |
| private MediaView | |
| public final EventHandler | |
| public final Rectangle2D | Returns: the rectangular viewport.Retrieves the rectangular viewport into the media frame. |
| public final double | Returns: the x coordinate of the origin of the view.Retrieves the x coordinate of the |
| public final double | Returns: the y coordinate of the origin of the view.Retrieves the y coordinate of the |
| public final boolean | Returns: whether the media aspect ratio is preserved.Returns whether the media aspect ratio is preserved when scaling. |
| public final boolean | |
| public final ObjectProperty | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| public final ObjectProperty | |
| pack-priv int | |
| pack-priv int | |
| pack-priv void | |
| public final BooleanProperty | |
| public final void | setFitHeight(double
the height of the resized media. value)Sets the height of the bounding box of the resized media. |
| public final void | setFitWidth(double
the width of the resized media. value)Sets the width of the bounding box of the resized media. |
| public final void | setMediaPlayer(MediaPlayer
the associated value)MediaPlayer.Sets the |
| public final void | setOnError(EventHandler<MediaErrorEvent>
the error event handler. value)Sets the error event handler. |
| public final void | setPreserveRatio(boolean
whether to preserve the media aspect ratio. value)Sets whether to preserve the media aspect ratio when scaling. |
| public final void | |
| public final void | setViewport(Rectangle2D
the rectangular viewport. value)Sets the rectangular viewport into the media frame. |
| public final void | setX(double
the x coordinate of the origin of the view. value)Sets the x coordinate of the |
| public final void | setY(double
the y coordinate of the origin of the view. value)Sets the y coordinate of the |
| public final BooleanProperty | |
| private void | |
| private synchronized void | |
| private synchronized void | |
| private synchronized void | |
| private void | |
| private synchronized void | |
| private synchronized void | |
| private synchronized void | |
| private synchronized void | |
| pack-priv void | |
| public final ObjectProperty | |
| public final DoubleProperty | |
| public final DoubleProperty |
| decodedFrameCount | back to summary |
|---|---|
| private int decodedFrameCount | |
| decodedFrameRateListener | back to summary |
|---|---|
| private VideoFrameRateListener decodedFrameRateListener Listener for decoded frame rate. | |
| DEFAULT_STYLE_CLASS | back to summary |
|---|---|
| private static final String DEFAULT_STYLE_CLASS | |
| errorListener | back to summary |
|---|---|
| private InvalidationListener errorListener Listener which converts | |
| fitHeight | back to summary |
|---|---|
| private DoubleProperty fitHeight Determines the height of the bounding box within which the source media is
resized as necessary to fit. If
See | |
| fitWidth | back to summary |
|---|---|
| private DoubleProperty fitWidth Determines the width of the bounding box within which the source media is
resized as necessary to fit. If
See | |
| mediaDimensionListener | back to summary |
|---|---|
| private InvalidationListener mediaDimensionListener Listener which causes the geometry to be updated when the media dimension changes. | |
| mediaPlayer | back to summary |
|---|---|
| private ObjectProperty<MediaPlayer> mediaPlayer The
| |
| mediaPlayerOverlay | back to summary |
|---|---|
| private MediaPlayerOverlay mediaPlayerOverlay | |
| onError | back to summary |
|---|---|
| private ObjectProperty<EventHandler<MediaErrorEvent>> onError Event handler to be invoked whenever an error occurs on this
| |
| opacityListener | back to summary |
|---|---|
| private ChangeListener<Number> opacityListener | |
| parentListener | back to summary |
|---|---|
| private ChangeListener<Parent> parentListener | |
| preserveRatio | back to summary |
|---|---|
| private BooleanProperty preserveRatio Whether to preserve the aspect ratio (width / height) of the media when
scaling it to fit the node. If the aspect ratio is not preserved, the
media will be stretched or sheared in both dimensions to fit the
dimensions of the node. The default value is | |
| registerVideoFrameRateListener | back to summary |
|---|---|
| private boolean registerVideoFrameRateListener | |
| renderedFrameCount | back to summary |
|---|---|
| private int renderedFrameCount | |
| smooth | back to summary |
|---|---|
| private BooleanProperty smooth If set to | |
| treeVisibleListener | back to summary |
|---|---|
| private ChangeListener<Boolean> treeVisibleListener | |
| VIDEO_FRAME_RATE_PROPERTY_NAME | back to summary |
|---|---|
| private static final String VIDEO_FRAME_RATE_PROPERTY_NAME The name of the property in the | |
| viewport | back to summary |
|---|---|
| private ObjectProperty<Rectangle2D> viewport Specifies a rectangular viewport into the media frame.
The viewport is a rectangle specified in the coordinates of the media frame.
The resulting bounds prior to scaling will
be the size of the viewport. The displayed image will include the
intersection of the frame and the viewport. The viewport can exceed the
size of the frame, but only the intersection will be displayed.
Setting | |
| x | back to summary |
|---|---|
| private DoubleProperty x Defines the current x coordinate of the | |
| y | back to summary |
|---|---|
| private DoubleProperty y Defines the current y coordinate of the | |
| MediaView | back to summary |
|---|---|
| public MediaView() Creates a | |
| MediaView | back to summary |
|---|---|
| public MediaView(MediaPlayer mediaPlayer) Creates a
| |
| _mediaPlayerOnReady | back to summary |
|---|---|
| pack-priv void _mediaPlayerOnReady() Called by MediaPlayer when it becomes ready | |
| calculateNodeToSceneTransform | back to summary |
|---|---|
| private static Affine3D calculateNodeToSceneTransform(Node node) | |
| createListeners | back to summary |
|---|---|
| private void createListeners() | |
| createVideoFrameRateListener | back to summary |
|---|---|
| private VideoFrameRateListener createVideoFrameRateListener() Creates a decoded frame rate listener. Will return | |
| determineVisibility | back to summary |
|---|---|
| private boolean determineVisibility() | |
| doComputeContains | back to summary |
|---|---|
| private boolean doComputeContains(double localX, double localY) | |
| doComputeGeomBounds | back to summary |
|---|---|
| private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) | |
| doCreatePeer | back to summary |
|---|---|
| private NGNode doCreatePeer() | |
| doTransformsChanged | back to summary |
|---|---|
| private void doTransformsChanged() | |
| doUpdatePeer | back to summary |
|---|---|
| private void doUpdatePeer() | |
| fitHeightProperty | back to summary |
|---|---|
| public final DoubleProperty fitHeightProperty() | |
| fitWidthProperty | back to summary |
|---|---|
| public final DoubleProperty fitWidthProperty() | |
| getFitHeight | back to summary |
|---|---|
| public final double getFitHeight() Retrieves the height of the bounding box of the resized media.
| |
| getFitWidth | back to summary |
|---|---|
| public final double getFitWidth() Retrieves the width of the bounding box of the resized media.
| |
| getMediaPlayer | back to summary |
|---|---|
| public final MediaPlayer getMediaPlayer() Retrieves the
| |
| getMediaView | back to summary |
|---|---|
private MediaView getMediaView()
| |
| getOnError | back to summary |
|---|---|
| public final EventHandler Retrieves the error event handler.
| |
| getViewport | back to summary |
|---|---|
| public final Rectangle2D getViewport() Retrieves the rectangular viewport into the media frame.
| |
| getX | back to summary |
|---|---|
| public final double getX() Retrieves the x coordinate of the
| |
| getY | back to summary |
|---|---|
| public final double getY() Retrieves the y coordinate of the
| |
| isPreserveRatio | back to summary |
|---|---|
| public final boolean isPreserveRatio() Returns whether the media aspect ratio is preserved when scaling.
| |
| isSmooth | back to summary |
|---|---|
| public final boolean isSmooth() Returns whether to smooth the media when scaling.
| |
| mediaPlayerProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| notifyMediaChange | back to summary |
|---|---|
| pack-priv void notifyMediaChange() | |
| notifyMediaFrameUpdated | back to summary |
|---|---|
| pack-priv void notifyMediaFrameUpdated() | |
| notifyMediaSizeChange | back to summary |
|---|---|
| pack-priv void notifyMediaSizeChange() | |
| onErrorProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| perfGetDecodedFrameCount | back to summary |
|---|---|
pack-priv int perfGetDecodedFrameCount()
| |
| perfGetRenderedFrameCount | back to summary |
|---|---|
pack-priv int perfGetRenderedFrameCount()
| |
| perfReset | back to summary |
|---|---|
| pack-priv void perfReset() | |
| preserveRatioProperty | back to summary |
|---|---|
| public final BooleanProperty preserveRatioProperty() | |
| setFitHeight | back to summary |
|---|---|
| public final void setFitHeight(double value) Sets the height of the bounding box of the resized media.
| |
| setFitWidth | back to summary |
|---|---|
| public final void setFitWidth(double value) Sets the width of the bounding box of the resized media.
| |
| setMediaPlayer | back to summary |
|---|---|
| public final void setMediaPlayer(MediaPlayer value) Sets the
| |
| setOnError | back to summary |
|---|---|
| public final void setOnError(EventHandler<MediaErrorEvent> value) Sets the error event handler.
| |
| setPreserveRatio | back to summary |
|---|---|
| public final void setPreserveRatio(boolean value) Sets whether to preserve the media aspect ratio when scaling.
| |
| setSmooth | back to summary |
|---|---|
| public final void setSmooth(boolean value) Sets whether to smooth the media when scaling.
| |
| setViewport | back to summary |
|---|---|
| public final void setViewport(Rectangle2D value) Sets the rectangular viewport into the media frame.
| |
| setX | back to summary |
|---|---|
| public final void setX(double value) Sets the x coordinate of the
| |
| setY | back to summary |
|---|---|
| public final void setY(double value) Sets the y coordinate of the
| |
| smoothProperty | back to summary |
|---|---|
| public final BooleanProperty smoothProperty() | |
| updateMediaPlayerOverlay | back to summary |
|---|---|
| private void updateMediaPlayerOverlay() | |
| updateOverlayHeight | back to summary |
|---|---|
| private synchronized void updateOverlayHeight() | |
| updateOverlayOpacity | back to summary |
|---|---|
| private synchronized void updateOverlayOpacity() | |
| updateOverlayPreserveRatio | back to summary |
|---|---|
| private synchronized void updateOverlayPreserveRatio() | |
| updateOverlayTransform | back to summary |
|---|---|
| private void updateOverlayTransform() | |
| updateOverlayVisibility | back to summary |
|---|---|
| private synchronized void updateOverlayVisibility() | |
| updateOverlayWidth | back to summary |
|---|---|
| private synchronized void updateOverlayWidth() | |
| updateOverlayX | back to summary |
|---|---|
| private synchronized void updateOverlayX() | |
| updateOverlayY | back to summary |
|---|---|
| private synchronized void updateOverlayY() | |
| updateViewport | back to summary |
|---|---|
| pack-priv void updateViewport() | |
| viewportProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| xProperty | back to summary |
|---|---|
| public final DoubleProperty xProperty() | |
| yProperty | back to summary |
|---|---|
| public final DoubleProperty yProperty() | |
MediaPlayer error into a
Bean event.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | invalidated(Observable value)
Implements javafx. This method needs to be provided by an implementation of
|
| MediaErrorInvalidationListener | back to summary |
|---|---|
| private MediaErrorInvalidationListener() | |
| invalidated | back to summary |
|---|---|
| public void invalidated(Observable value) Implements javafx. Doc from javafx. This method needs to be provided by an implementation of
In general, it is considered bad practice to modify the observed value in this method.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void |
| MediaViewFrameTracker | back to summary |
|---|---|
| private MediaViewFrameTracker() | |
| incrementDecodedFrameCount | back to summary |
|---|---|
| public void incrementDecodedFrameCount(int count) Implements com.
| |
| incrementRenderedFrameCount | back to summary |
|---|---|
| public void incrementRenderedFrameCount(int count) Implements com.
| |