Class MediaView
- All Implemented Interfaces:
-
Styleable,EventTarget
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: - Since:
- JavaFX 2.0
Property Summary
| Type | Property | Description |
|---|---|---|
final DoubleProperty |
fitHeight |
Determines the height of the bounding box within which the source media is resized as necessary to fit. |
final DoubleProperty |
fitWidth |
Determines the width of the bounding box within which the source media is resized as necessary to fit. |
final ObjectProperty<MediaPlayer> |
mediaPlayer |
The mediaPlayer whose output will be handled by this view. |
final ObjectProperty<EventHandler<MediaErrorEvent>> |
onError |
Event handler to be invoked whenever an error occurs on this MediaView. |
final BooleanProperty |
preserveRatio |
Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the node. |
final 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. |
final ObjectProperty<Rectangle2D> |
viewport |
Specifies a rectangular viewport into the media frame. |
final DoubleProperty |
x |
Defines the current x coordinate of the MediaView origin. |
final DoubleProperty |
y |
Defines the current y coordinate of the MediaView origin. |
Properties declared in class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
Field Summary
Fields declared in class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor Summary
| Constructor | Description |
|---|---|
MediaView() |
Creates a MediaView instance with no associated MediaPlayer. |
MediaView |
Creates a MediaView instance associated with the specified MediaPlayer. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
final DoubleProperty |
fitHeightProperty() |
Determines the height of the bounding box within which the source media is resized as necessary to fit. |
final DoubleProperty |
fitWidthProperty() |
Determines the width of the bounding box within which the source media is resized as necessary to fit. |
final double |
getFitHeight() |
Retrieves the height of the bounding box of the resized media. |
final double |
getFitWidth() |
Retrieves the width of the bounding box of the resized media. |
final MediaPlayer |
getMediaPlayer() |
Retrieves the MediaPlayer whose output is being handled by this view. |
final EventHandler<MediaErrorEvent> |
getOnError() |
Retrieves the error event handler. |
final Rectangle2D |
getViewport() |
Retrieves the rectangular viewport into the media frame. |
final double |
getX() |
Retrieves the x coordinate of the MediaView origin. |
final double |
getY() |
Retrieves the y coordinate of the MediaView origin. |
final boolean |
isPreserveRatio() |
Returns whether the media aspect ratio is preserved when scaling. |
final boolean |
isSmooth() |
Returns whether to smooth the media when scaling. |
final ObjectProperty<MediaPlayer> |
mediaPlayerProperty() |
The mediaPlayer whose output will be handled by this view. |
final ObjectProperty<EventHandler<MediaErrorEvent>> |
onErrorProperty() |
Event handler to be invoked whenever an error occurs on this MediaView. |
final BooleanProperty |
preserveRatioProperty() |
Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the node. |
final void |
setFitHeight |
Sets the height of the bounding box of the resized media. |
final void |
setFitWidth |
Sets the width of the bounding box of the resized media. |
final void |
setMediaPlayer |
Sets the MediaPlayer whose output will be handled by this view. |
final void |
setOnError |
Sets the error event handler. |
final void |
setPreserveRatio |
Sets whether to preserve the media aspect ratio when scaling. |
final void |
setSmooth |
Sets whether to smooth the media when scaling. |
final void |
setViewport |
Sets the rectangular viewport into the media frame. |
final void |
setX |
Sets the x coordinate of the MediaView origin. |
final void |
setY |
Sets the y coordinate of the MediaView origin. |
final BooleanProperty |
smoothProperty() |
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. |
final ObjectProperty<Rectangle2D> |
viewportProperty() |
Specifies a rectangular viewport into the media frame. |
final DoubleProperty |
xProperty() |
Defines the current x coordinate of the MediaView origin. |
final DoubleProperty |
yProperty() |
Defines the current y coordinate of the MediaView origin. |
Methods declared in class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBaselineOffset, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClassCssMetaData, getClip, getContentBias, getCssMetaData, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, 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, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, 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, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
Property Details
mediaPlayer
public final ObjectProperty<MediaPlayer> mediaPlayerProperty
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.onError
public final ObjectProperty<EventHandler<MediaErrorEvent>> onErrorProperty
MediaView.preserveRatio
public final BooleanProperty preserveRatioProperty
true.smooth
public final BooleanProperty smoothProperty
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.- See Also:
x
public final DoubleProperty xProperty
MediaView origin.- See Also:
y
public final DoubleProperty yProperty
MediaView origin.- See Also:
fitWidth
public final DoubleProperty fitWidthProperty
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.
fitHeight
public final DoubleProperty fitHeightProperty
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.
viewport
public final ObjectProperty<Rectangle2D> viewportProperty
viewport to null will clear the viewport.Constructor Details
MediaView
public MediaView()
MediaView instance with no associated MediaPlayer.MediaView
public MediaView(MediaPlayer mediaPlayer)
MediaView instance associated with the specified MediaPlayer. Equivalent to
MediaPlayer player; // initialization omitted
MediaView view = new MediaView();
view.setMediaPlayer(player);
- Parameters:
-
mediaPlayer- theMediaPlayerthe playback of which is to be viewed via this class.
Method Details
setMediaPlayer
public final void setMediaPlayer(MediaPlayer value)
MediaPlayer whose output will be handled by this view.- Parameters:
-
value- the associatedMediaPlayer.
getMediaPlayer
public final MediaPlayer getMediaPlayer()
MediaPlayer whose output is being handled by this view.- Returns:
- the associated
MediaPlayer.
mediaPlayerProperty
public final ObjectProperty<MediaPlayer> mediaPlayerProperty()
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.- Returns:
- the
mediaPlayerproperty - See Also:
setOnError
public final void setOnError(EventHandler<MediaErrorEvent> value)
- Parameters:
-
value- the error event handler.
getOnError
public final EventHandler<MediaErrorEvent> getOnError()
- Returns:
- the error event handler.
onErrorProperty
public final ObjectProperty<EventHandler<MediaErrorEvent>> onErrorProperty()
MediaView.- Returns:
- the
onErrorproperty - See Also:
setPreserveRatio
public final void setPreserveRatio(boolean value)
- Parameters:
-
value- whether to preserve the media aspect ratio.
isPreserveRatio
public final boolean isPreserveRatio()
- Returns:
- whether the media aspect ratio is preserved.
preserveRatioProperty
public final BooleanProperty preserveRatioProperty()
true.- Returns:
- the
preserveRatioproperty - See Also:
setSmooth
public final void setSmooth(boolean value)
- Parameters:
-
value- whether to smooth the media.
isSmooth
public final boolean isSmooth()
- Returns:
- whether to smooth the media
smoothProperty
public final BooleanProperty smoothProperty()
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.- Returns:
- the
smoothproperty - See Also:
setX
public final void setX(double value)
MediaView origin.- Parameters:
-
value- the x coordinate of the origin of the view.
getX
public final double getX()
MediaView origin.- Returns:
- the x coordinate of the origin of the view.
xProperty
public final DoubleProperty xProperty()
MediaView origin.- Returns:
- the
xproperty - See Also:
setY
public final void setY(double value)
MediaView origin.- Parameters:
-
value- the y coordinate of the origin of the view.
getY
public final double getY()
MediaView origin.- Returns:
- the y coordinate of the origin of the view.
yProperty
public final DoubleProperty yProperty()
MediaView origin.- Returns:
- the
yproperty - See Also:
setFitWidth
public final void setFitWidth(double value)
- Parameters:
-
value- the width of the resized media.
getFitWidth
public final double getFitWidth()
- Returns:
- the height of the resized media.
fitWidthProperty
public final DoubleProperty fitWidthProperty()
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.
- Returns:
- the
fitWidthproperty - See Also:
setFitHeight
public final void setFitHeight(double value)
- Parameters:
-
value- the height of the resized media.
getFitHeight
public final double getFitHeight()
- Returns:
- the height of the resized media.
fitHeightProperty
public final DoubleProperty fitHeightProperty()
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.
- Returns:
- the
fitHeightproperty - See Also:
setViewport
public final void setViewport(Rectangle2D value)
- Parameters:
-
value- the rectangular viewport.
getViewport
public final Rectangle2D getViewport()
- Returns:
- the rectangular viewport.
viewportProperty
public final ObjectProperty<Rectangle2D> viewportProperty()
viewport to null will clear the viewport.- Returns:
- the
viewportproperty - See Also:
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.