public class MediaView extends Node
Node
that provides a view of Media
being played by a
MediaPlayer
.
The following code snippet provides a simple example of an
Application.start()
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.MediaErrorInvalidationListener
Inner class used to convert a
MediaPlayer error into a
Bean event. |
private class |
MediaView.MediaViewFrameTracker |
Modifier and Type | Field and Description |
---|---|
private int |
decodedFrameCount |
private VideoFrameRateListener |
decodedFrameRateListener
Listener for decoded frame rate.
|
private static java.lang.String |
DEFAULT_STYLE_CLASS |
private InvalidationListener |
errorListener
Listener which converts
MediaPlayer errors to events. |
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> |
mediaPlayer
The
mediaPlayer whose output will be handled by this view. |
private MediaPlayerOverlay |
mediaPlayerOverlay
Media Player Overlay support
|
private ObjectProperty<EventHandler<MediaErrorEvent>> |
onError
Event handler to be invoked whenever an error occurs on this
MediaView . |
private ChangeListener<java.lang.Number> |
opacityListener |
private ChangeListener<Parent> |
parentListener |
private BooleanProperty |
preserveRatio
Whether to preserve the aspect ratio (width / height) of the media when
scaling it to fit the node.
|
private boolean |
registerVideoFrameRateListener |
private int |
renderedFrameCount |
private BooleanProperty |
smooth
If set to
true a better quality filtering
algorithm will be used when scaling this video to fit within the
bounding box provided by fitWidth and fitHeight or
when transforming. |
private ChangeListener<java.lang.Boolean> |
treeVisibleListener |
private static java.lang.String |
VIDEO_FRAME_RATE_PROPERTY_NAME
The name of the property in the
ObservableMap returned by
Node.getProperties() . |
private ObjectProperty<Rectangle2D> |
viewport
Specifies a rectangular viewport into the media frame.
|
private DoubleProperty |
x
Defines the current x coordinate of the
MediaView origin. |
private DoubleProperty |
y
Defines the current y coordinate of the
MediaView origin. |
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor and Description |
---|
MediaView()
Creates a
MediaView instance with no associated
MediaPlayer . |
MediaView(MediaPlayer mediaPlayer)
Creates a
MediaView instance associated with the specified
MediaPlayer . |
Modifier and Type | Method and Description |
---|---|
(package private) void |
_mediaPlayerOnReady()
Called by MediaPlayer when it becomes ready
|
private static Affine3D |
calculateNodeToSceneTransform(Node node) |
private void |
createListeners() |
private VideoFrameRateListener |
createVideoFrameRateListener()
Creates a decoded frame rate listener.
|
private boolean |
determineVisibility() |
DoubleProperty |
fitHeightProperty() |
DoubleProperty |
fitWidthProperty() |
double |
getFitHeight()
Retrieves the height of the bounding box of the resized media.
|
double |
getFitWidth()
Retrieves the width of the bounding box of the resized media.
|
MediaPlayer |
getMediaPlayer()
Retrieves the
MediaPlayer whose output is being handled by
this view. |
private MediaView |
getMediaView() |
EventHandler<MediaErrorEvent> |
getOnError()
Retrieves the error event handler.
|
Rectangle2D |
getViewport()
Retrieves the rectangular viewport into the media frame.
|
double |
getX()
Retrieves the x coordinate of the
MediaView origin. |
double |
getY()
Retrieves the y coordinate of the
MediaView origin. |
protected boolean |
impl_computeContains(double localX,
double localY)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
BaseBounds |
impl_computeGeomBounds(BaseBounds bounds,
BaseTransform tx)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
protected NGNode |
impl_createPeer()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
int |
impl_perfGetDecodedFrameCount()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
int |
impl_perfGetRenderedFrameCount()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
void |
impl_perfReset()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
java.lang.Object |
impl_processMXNode(MXNodeAlgorithm alg,
MXNodeAlgorithmContext ctx)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
void |
impl_transformsChanged()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
void |
impl_updatePeer()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
boolean |
isPreserveRatio()
Returns whether the media aspect ratio is preserved when scaling.
|
boolean |
isSmooth()
Returns whether to smooth the media when scaling.
|
ObjectProperty<MediaPlayer> |
mediaPlayerProperty() |
(package private) void |
notifyMediaChange() |
(package private) void |
notifyMediaFrameUpdated() |
(package private) void |
notifyMediaSizeChange() |
ObjectProperty<EventHandler<MediaErrorEvent>> |
onErrorProperty() |
BooleanProperty |
preserveRatioProperty() |
void |
setFitHeight(double value)
Sets the height of the bounding box of the resized media.
|
void |
setFitWidth(double value)
Sets the width of the bounding box of the resized media.
|
void |
setMediaPlayer(MediaPlayer value)
Sets the
MediaPlayer whose output will be handled by this view. |
void |
setOnError(EventHandler<MediaErrorEvent> value)
Sets the error event handler.
|
void |
setPreserveRatio(boolean value)
Sets whether to preserve the media aspect ratio when scaling.
|
void |
setSmooth(boolean value)
Sets whether to smooth the media when scaling.
|
void |
setViewport(Rectangle2D value)
Sets the rectangular viewport into the media frame.
|
void |
setX(double value)
Sets the x coordinate of the
MediaView origin. |
void |
setY(double value)
Sets the y coordinate of the
MediaView origin. |
BooleanProperty |
smoothProperty() |
private void |
updateMediaPlayerOverlay() |
private void |
updateOverlayHeight() |
private void |
updateOverlayOpacity() |
private void |
updateOverlayPreserveRatio() |
private void |
updateOverlayTransform() |
private void |
updateOverlayVisibility() |
private void |
updateOverlayWidth() |
private void |
updateOverlayX() |
private void |
updateOverlayY() |
(package private) void |
updateViewport() |
ObjectProperty<Rectangle2D> |
viewportProperty() |
DoubleProperty |
xProperty() |
DoubleProperty |
yProperty() |
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, containsBounds, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBaselineOffset, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClassCssMetaData, getClip, getContentBias, getCssMetaData, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, hasProperties, hoverProperty, idProperty, impl_clearDirty, impl_computeIntersects, impl_computeLayoutBounds, impl_cssGetCursorInitialValue, impl_cssGetFocusTraversableInitialValue, impl_findStyles, impl_geomChanged, impl_getLeafTransform, impl_getMatchingStyles, impl_getPeer, impl_getPivotX, impl_getPivotY, impl_getPivotZ, impl_getStyleMap, impl_hasTransforms, impl_intersects, impl_intersectsBounds, impl_isDirty, impl_isDirtyEmpty, impl_isShowMnemonics, impl_isTreeVisible, impl_layoutBoundsChanged, impl_markDirty, impl_notifyLayoutBoundsChanged, impl_pickNode, impl_pickNodeLocal, impl_processCSS, impl_processCSS, impl_reapplyCSS, impl_setShowMnemonics, impl_setStyleMap, impl_showMnemonicsProperty, impl_syncPeer, impl_traverse, impl_treeVisibleProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isResizable, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, maxHeight, maxWidth, minHeight, minWidth, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, prefHeight, prefWidth, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, resize, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, visibleProperty
private static final java.lang.String VIDEO_FRAME_RATE_PROPERTY_NAME
ObservableMap
returned by
Node.getProperties()
. This value must also be defined as a JVM
command line definition for the frame rate to be added to the properties.private static final java.lang.String DEFAULT_STYLE_CLASS
private InvalidationListener errorListener
MediaPlayer
errors to events.private InvalidationListener mediaDimensionListener
private VideoFrameRateListener decodedFrameRateListener
private boolean registerVideoFrameRateListener
private MediaPlayerOverlay mediaPlayerOverlay
private ChangeListener<Parent> parentListener
private ChangeListener<java.lang.Boolean> treeVisibleListener
private ChangeListener<java.lang.Number> opacityListener
private ObjectProperty<MediaPlayer> mediaPlayer
mediaPlayer
whose output will be handled by this view.
Setting this value does not affect the status of the MediaPlayer
,
e.g., if the MediaPlayer
was playing prior to setting
mediaPlayer
then it will continue playing.MediaException
,
MediaPlayer
private ObjectProperty<EventHandler<MediaErrorEvent>> onError
MediaView
.MediaErrorEvent
private BooleanProperty preserveRatio
true
.private BooleanProperty smooth
true
a better quality filtering
algorithm will be used when scaling this video to fit within the
bounding box provided by fitWidth
and fitHeight
or
when transforming.
If set to false
a faster but lesser quality filtering
will be used.
The default value depends on platform configuration.private DoubleProperty x
MediaView
origin.private DoubleProperty y
MediaView
origin.private DoubleProperty fitWidth
value ≤ 0
, then the width
of the bounding box will be set to the natural width of the media, but
fitWidth
will be set to the supplied parameter, even if
non-positive.
See preserveRatio
for information on interaction
between media views fitWidth
, fitHeight
and
preserveRatio
attributes.
private DoubleProperty fitHeight
value ≤ 0
, then the height
of the bounding box will be set to the natural height of the media, but
fitHeight
will be set to the supplied parameter, even if
non-positive.
See preserveRatio
for information on interaction
between media views fitWidth
, fitHeight
and
preserveRatio
attributes.
private ObjectProperty<Rectangle2D> viewport
viewport
to null will clear the viewport.private int decodedFrameCount
private int renderedFrameCount
public MediaView()
MediaView
instance with no associated
MediaPlayer
.public MediaView(MediaPlayer mediaPlayer)
MediaView
instance associated with the specified
MediaPlayer
. Equivalent to
MediaPlayer player; // initialization omitted
MediaView view = new MediaView();
view.setMediaPlayer(player);
mediaPlayer
- the MediaPlayer
the playback of which is to be
viewed via this class.private VideoFrameRateListener createVideoFrameRateListener()
null
if
the security manager does not permit retrieve system properties or if
VIDEO_FRAME_RATE_PROPERTY_NAME is not set to "true."private void createListeners()
private boolean determineVisibility()
private void updateOverlayVisibility()
private void updateOverlayOpacity()
private void updateOverlayX()
private void updateOverlayY()
private void updateOverlayWidth()
private void updateOverlayHeight()
private void updateOverlayPreserveRatio()
private void updateOverlayTransform()
private void updateMediaPlayerOverlay()
@Deprecated public void impl_transformsChanged()
Node
impl_transformsChanged
in class Node
private MediaView getMediaView()
public final void setMediaPlayer(MediaPlayer value)
MediaPlayer
whose output will be handled by this view.value
- the associated MediaPlayer
.public final MediaPlayer getMediaPlayer()
MediaPlayer
whose output is being handled by
this view.MediaPlayer
.public final ObjectProperty<MediaPlayer> mediaPlayerProperty()
public final void setOnError(EventHandler<MediaErrorEvent> value)
value
- the error event handler.public final EventHandler<MediaErrorEvent> getOnError()
public final ObjectProperty<EventHandler<MediaErrorEvent>> onErrorProperty()
public final void setPreserveRatio(boolean value)
value
- whether to preserve the media aspect ratio.public final boolean isPreserveRatio()
public final BooleanProperty preserveRatioProperty()
public final void setSmooth(boolean value)
value
- whether to smooth the media.public final boolean isSmooth()
public final BooleanProperty smoothProperty()
public final void setX(double value)
MediaView
origin.value
- the x coordinate of the origin of the view.public final double getX()
MediaView
origin.public final DoubleProperty xProperty()
public final void setY(double value)
MediaView
origin.value
- the y coordinate of the origin of the view.public final double getY()
MediaView
origin.public final DoubleProperty yProperty()
public final void setFitWidth(double value)
value
- the width of the resized media.public final double getFitWidth()
public final DoubleProperty fitWidthProperty()
public final void setFitHeight(double value)
value
- the height of the resized media.public final double getFitHeight()
public final DoubleProperty fitHeightProperty()
public final void setViewport(Rectangle2D value)
value
- the rectangular viewport.public final Rectangle2D getViewport()
public final ObjectProperty<Rectangle2D> viewportProperty()
void notifyMediaChange()
void notifyMediaSizeChange()
void notifyMediaFrameUpdated()
@Deprecated protected NGNode impl_createPeer()
impl_createPeer
in class Node
@Deprecated public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx)
Node
impl_computeGeomBounds
in class Node
@Deprecated protected boolean impl_computeContains(double localX, double localY)
impl_computeContains
in class Node
void updateViewport()
@Deprecated public void impl_updatePeer()
Node
impl_updatePeer
in class Node
@Deprecated public void impl_perfReset()
@Deprecated public int impl_perfGetDecodedFrameCount()
@Deprecated public int impl_perfGetRenderedFrameCount()
@Deprecated public java.lang.Object impl_processMXNode(MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx)
Node
impl_processMXNode
in class Node
alg
- current algorithm to process this nodectx
- current contextvoid _mediaPlayerOnReady()