java.lang.Object
javafx.scene.Node
javafx.scene.media.MediaView
- All Implemented Interfaces:
- Styleable,- EventTarget
public class MediaView extends Node
A 
 
 
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);
 }
 
- Since:
- JavaFX 2.0
- 
Property SummaryProperties Type Property Description DoublePropertyfitHeightDetermines the height of the bounding box within which the source media is resized as necessary to fit.DoublePropertyfitWidthDetermines the width of the bounding box within which the source media is resized as necessary to fit.ObjectProperty<MediaPlayer>mediaPlayerThemediaPlayerwhose output will be handled by this view.ObjectProperty<EventHandler<MediaErrorEvent>>onErrorEvent handler to be invoked whenever an error occurs on thisMediaView.BooleanPropertypreserveRatioWhether to preserve the aspect ratio (width / height) of the media when scaling it to fit the node.BooleanPropertysmoothIf set totruea better quality filtering algorithm will be used when scaling this video to fit within the bounding box provided byfitWidthandfitHeightor when transforming.ObjectProperty<Rectangle2D>viewportSpecifies a rectangular viewport into the media frame.DoublePropertyxDefines the current x coordinate of theMediaVieworigin.DoublePropertyyDefines the current y coordinate of theMediaVieworigin.Properties declared in class javafx.scene.NodeaccessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, 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 SummaryFields declared in class javafx.scene.NodeBASELINE_OFFSET_SAME_AS_HEIGHT
- 
Constructor SummaryConstructors Constructor Description MediaView()Creates aMediaViewinstance with no associatedMediaPlayer.MediaView(MediaPlayer mediaPlayer)Creates aMediaViewinstance associated with the specifiedMediaPlayer.
- 
Method SummaryModifier and Type Method Description DoublePropertyfitHeightProperty()Determines the height of the bounding box within which the source media is resized as necessary to fit.DoublePropertyfitWidthProperty()Determines the width of the bounding box within which the source media is resized as necessary to fit.doublegetFitHeight()Retrieves the height of the bounding box of the resized media.doublegetFitWidth()Retrieves the width of the bounding box of the resized media.MediaPlayergetMediaPlayer()Retrieves theMediaPlayerwhose output is being handled by this view.EventHandler<MediaErrorEvent>getOnError()Retrieves the error event handler.Rectangle2DgetViewport()Retrieves the rectangular viewport into the media frame.doublegetX()Retrieves the x coordinate of theMediaVieworigin.doublegetY()Retrieves the y coordinate of theMediaVieworigin.booleanisPreserveRatio()Returns whether the media aspect ratio is preserved when scaling.booleanisSmooth()Returns whether to smooth the media when scaling.ObjectProperty<MediaPlayer>mediaPlayerProperty()ThemediaPlayerwhose output will be handled by this view.ObjectProperty<EventHandler<MediaErrorEvent>>onErrorProperty()Event handler to be invoked whenever an error occurs on thisMediaView.BooleanPropertypreserveRatioProperty()Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the node.voidsetFitHeight(double value)Sets the height of the bounding box of the resized media.voidsetFitWidth(double value)Sets the width of the bounding box of the resized media.voidsetMediaPlayer(MediaPlayer value)Sets theMediaPlayerwhose output will be handled by this view.voidsetOnError(EventHandler<MediaErrorEvent> value)Sets the error event handler.voidsetPreserveRatio(boolean value)Sets whether to preserve the media aspect ratio when scaling.voidsetSmooth(boolean value)Sets whether to smooth the media when scaling.voidsetViewport(Rectangle2D value)Sets the rectangular viewport into the media frame.voidsetX(double value)Sets the x coordinate of theMediaVieworigin.voidsetY(double value)Sets the y coordinate of theMediaVieworigin.BooleanPropertysmoothProperty()If set totruea better quality filtering algorithm will be used when scaling this video to fit within the bounding box provided byfitWidthandfitHeightor when transforming.ObjectProperty<Rectangle2D>viewportProperty()Specifies a rectangular viewport into the media frame.DoublePropertyxProperty()Defines the current x coordinate of theMediaVieworigin.DoublePropertyyProperty()Defines the current y coordinate of theMediaVieworigin.Methods declared in class javafx.scene.NodeaccessibleHelpProperty, 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, 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, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, 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, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visiblePropertyMethods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods declared in interface javafx.css.StyleablegetStyleableNode, getStyleClass
- 
Property Details- 
mediaPlayerThemediaPlayerwhose output will be handled by this view. Setting this value does not affect the status of theMediaPlayer, e.g., if theMediaPlayerwas playing prior to settingmediaPlayerthen it will continue playing.- See Also:
- getMediaPlayer(),- setMediaPlayer(MediaPlayer)
 
- 
onErrorEvent handler to be invoked whenever an error occurs on thisMediaView.- See Also:
- getOnError(),- setOnError(EventHandler)
 
- 
preserveRatioWhether 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 istrue.- See Also:
- isPreserveRatio(),- setPreserveRatio(boolean)
 
- 
smoothIf set totruea better quality filtering algorithm will be used when scaling this video to fit within the bounding box provided byfitWidthandfitHeightor when transforming. If set tofalsea faster but lesser quality filtering will be used. The default value depends on platform configuration.- See Also:
- isSmooth(),- setSmooth(boolean)
 
- 
xDefines the current x coordinate of theMediaVieworigin.- See Also:
- getX(),- setX(double)
 
- 
yDefines the current y coordinate of theMediaVieworigin.- See Also:
- getY(),- setY(double)
 
- 
fitWidthDetermines the width of the bounding box within which the source media is resized as necessary to fit. Ifvalue ≤ 0, then the width of the bounding box will be set to the natural width of the media, butfitWidthwill be set to the supplied parameter, even if non-positive.See preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- See Also:
- getFitWidth(),- setFitWidth(double)
 
- 
fitHeightDetermines the height of the bounding box within which the source media is resized as necessary to fit. Ifvalue ≤ 0, then the height of the bounding box will be set to the natural height of the media, butfitHeightwill be set to the supplied parameter, even if non-positive.See preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- See Also:
- getFitHeight(),- setFitHeight(double)
 
- 
viewportSpecifies 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. Settingviewportto null will clear the viewport.- See Also:
- getViewport(),- setViewport(Rectangle2D)
 
 
- 
- 
Constructor Details- 
MediaViewpublic MediaView()Creates aMediaViewinstance with no associatedMediaPlayer.
- 
MediaViewCreates aMediaViewinstance associated with the specifiedMediaPlayer. Equivalent toMediaPlayer player; // initialization omitted MediaView view = new MediaView(); view.setMediaPlayer(player);- Parameters:
- mediaPlayer- the- MediaPlayerthe playback of which is to be viewed via this class.
 
 
- 
- 
Method Details- 
setMediaPlayerSets theMediaPlayerwhose output will be handled by this view.- Parameters:
- value- the associated- MediaPlayer.
 
- 
getMediaPlayerRetrieves theMediaPlayerwhose output is being handled by this view.- Returns:
- the associated MediaPlayer.
 
- 
mediaPlayerPropertyThemediaPlayerwhose output will be handled by this view. Setting this value does not affect the status of theMediaPlayer, e.g., if theMediaPlayerwas playing prior to settingmediaPlayerthen it will continue playing.- See Also:
- getMediaPlayer(),- setMediaPlayer(MediaPlayer)
 
- 
setOnErrorSets the error event handler.- Parameters:
- value- the error event handler.
 
- 
getOnErrorRetrieves the error event handler.- Returns:
- the error event handler.
 
- 
onErrorPropertyEvent handler to be invoked whenever an error occurs on thisMediaView.- See Also:
- getOnError(),- setOnError(EventHandler)
 
- 
setPreserveRatiopublic final void setPreserveRatio(boolean value)Sets whether to preserve the media aspect ratio when scaling.- Parameters:
- value- whether to preserve the media aspect ratio.
 
- 
isPreserveRatiopublic final boolean isPreserveRatio()Returns whether the media aspect ratio is preserved when scaling.- Returns:
- whether the media aspect ratio is preserved.
 
- 
preserveRatioPropertyWhether 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 istrue.- See Also:
- isPreserveRatio(),- setPreserveRatio(boolean)
 
- 
setSmoothpublic final void setSmooth(boolean value)Sets whether to smooth the media when scaling.- Parameters:
- value- whether to smooth the media.
 
- 
isSmoothpublic final boolean isSmooth()Returns whether to smooth the media when scaling.- Returns:
- whether to smooth the media
 
- 
smoothPropertyIf set totruea better quality filtering algorithm will be used when scaling this video to fit within the bounding box provided byfitWidthandfitHeightor when transforming. If set tofalsea faster but lesser quality filtering will be used. The default value depends on platform configuration.- See Also:
- isSmooth(),- setSmooth(boolean)
 
- 
setXpublic final void setX(double value)Sets the x coordinate of theMediaVieworigin.- Parameters:
- value- the x coordinate of the origin of the view.
 
- 
getXpublic final double getX()Retrieves the x coordinate of theMediaVieworigin.- Returns:
- the x coordinate of the origin of the view.
 
- 
xPropertyDefines the current x coordinate of theMediaVieworigin.- See Also:
- getX(),- setX(double)
 
- 
setYpublic final void setY(double value)Sets the y coordinate of theMediaVieworigin.- Parameters:
- value- the y coordinate of the origin of the view.
 
- 
getYpublic final double getY()Retrieves the y coordinate of theMediaVieworigin.- Returns:
- the y coordinate of the origin of the view.
 
- 
yPropertyDefines the current y coordinate of theMediaVieworigin.- See Also:
- getY(),- setY(double)
 
- 
setFitWidthpublic final void setFitWidth(double value)Sets the width of the bounding box of the resized media.- Parameters:
- value- the width of the resized media.
 
- 
getFitWidthpublic final double getFitWidth()Retrieves the width of the bounding box of the resized media.- Returns:
- the height of the resized media.
 
- 
fitWidthPropertyDetermines the width of the bounding box within which the source media is resized as necessary to fit. Ifvalue ≤ 0, then the width of the bounding box will be set to the natural width of the media, butfitWidthwill be set to the supplied parameter, even if non-positive.See preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- See Also:
- getFitWidth(),- setFitWidth(double)
 
- 
setFitHeightpublic final void setFitHeight(double value)Sets the height of the bounding box of the resized media.- Parameters:
- value- the height of the resized media.
 
- 
getFitHeightpublic final double getFitHeight()Retrieves the height of the bounding box of the resized media.- Returns:
- the height of the resized media.
 
- 
fitHeightPropertyDetermines the height of the bounding box within which the source media is resized as necessary to fit. Ifvalue ≤ 0, then the height of the bounding box will be set to the natural height of the media, butfitHeightwill be set to the supplied parameter, even if non-positive.See preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- See Also:
- getFitHeight(),- setFitHeight(double)
 
- 
setViewportSets the rectangular viewport into the media frame.- Parameters:
- value- the rectangular viewport.
 
- 
getViewportRetrieves the rectangular viewport into the media frame.- Returns:
- the rectangular viewport.
 
- 
viewportPropertySpecifies 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. Settingviewportto null will clear the viewport.- See Also:
- getViewport(),- setViewport(Rectangle2D)
 
 
-