Class MediaView

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
one.jpro.platform.media.MediaView
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget
Direct Known Subclasses:
FXMediaPlayerView, FXMediaRecorderView, WebMediaView

public abstract class MediaView extends javafx.scene.layout.Region
Provides a view of MediaSource being played by a MediaPlayer or being recorded by a MediaRecorder.

The following code snippet provides a simple example of how to display a video:


 public void start(Stage stage) {
     // Get the media source as an application argument.
     String source = getParameters().getRaw().get(0);
     MediaSource mediaSource = new MediaSource(source);

     // Create the player and set to play automatically.
     MediaPlayer mediaPlayer = MediaPlayer.create(stage, mediaSource);
     mediaPlayer.setAutoPlay(true);

     // Create the view.
     MediaView mediaView = MediaView.create(mediaPlayer);

     // Create the Scene and add the view.
     Scene scene = new Scene(mediaView, 640, 480);
     stage.setScene(scene);

     // Name and display the Stage.
     stage.setTitle("Hello JPro Media Player");
     stage.show();
 }
 

The next code snippet provides a simple example of how to display the video from the camera while recording:


 public void start(Stage stage) {
     // Create the camera recorder.
     MediaRecorder mediaRecorder = MediaRecorder.create(stage);

     // Create the enable camera button and add it to a pane.
     Button enableCamButton = new Button("Enable Camera");
     StackPane previewPane = new StackPane(enableCamButton);

     // Create the camera view.
     MediaView cameraView = MediaView.create(mediaRecorder);

     // Set an event handler to enable the camera recording.
     enableCamButton.setOnAction(event -> {
          mediaRecorder.enable();
          previewPane.getChildren().setAll(cameraView);
     });

     // Create the Scene and add the preview pane.
     Scene scene = new Scene(previewPane, 640, 480);
     stage.setScene(scene);

     // Name and display the Stage.
     stage.setTitle("Hello JPro Media Player");
     stage.show();
 }
 
Author:
Besmir Beqiri
See Also:
  • Property Summary

    Properties
    Type
    Property
    Description
    abstract javafx.beans.property.DoubleProperty
    Determines the height of the bounding box within which the source media is resized as necessary to fit.
    abstract javafx.beans.property.DoubleProperty
    Determines the width of the bounding box within which the source media is resized as necessary to fit.
    abstract javafx.beans.property.ObjectProperty<MediaEngine>
    Attach the media engine that could be a MediaPlayer or MediaRecorder.
    abstract javafx.beans.property.BooleanProperty
    Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the view.

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, 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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    protected javafx.beans.property.DoubleProperty
     
    protected javafx.beans.property.DoubleProperty
     
    protected javafx.beans.property.ObjectProperty<MediaEngine>
     
    protected javafx.beans.property.BooleanProperty
     

    Fields inherited from class javafx.scene.layout.Region

    USE_COMPUTED_SIZE, USE_PREF_SIZE

    Fields inherited from class javafx.scene.Node

    BASELINE_OFFSET_SAME_AS_HEIGHT
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static MediaView
    create(javafx.stage.Stage stage)
    Creates a media view.
    static MediaView
    create(MediaPlayer mediaPlayer)
    Creates a media view for the given media player.
    static MediaView
    create(MediaRecorder mediaRecorder)
    Creates a media view for the given media recorder.
    abstract javafx.beans.property.DoubleProperty
    Determines the height of the bounding box within which the source media is resized as necessary to fit.
    abstract javafx.beans.property.DoubleProperty
    Determines the width of the bounding box within which the source media is resized as necessary to fit.
    final double
    Retrieves the height of the bounding box of the resized media.
    final double
    Retrieves the width of the bounding box of the resized media.
    Return the current media engine.
    final boolean
    Returns whether the media aspect ratio is preserved when scaling.
    protected void
     
    abstract javafx.beans.property.ObjectProperty<MediaEngine>
    Attach the media engine that could be a MediaPlayer or MediaRecorder.
    abstract javafx.beans.property.BooleanProperty
    Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the view.
    final void
    setFitHeight(double value)
    Sets the height of the bounding box of the resized media.
    final void
    setFitWidth(double value)
    Sets the width of the bounding box of the resized media.
    final void
    Sets the current media engine, like a MediaPlayer or a MediaRecorder.
    final void
    setPreserveRatio(boolean value)
    Sets whether to preserve the media aspect ratio when scaling.

    Methods inherited from class javafx.scene.layout.Region

    backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getBackground, getBorder, getClassCssMetaData, getCssMetaData, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty

    Methods inherited from class javafx.scene.Parent

    getBaselineOffset, getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, queryAccessibleAttribute, requestLayout, requestParentLayout, setNeedsLayout, updateBounds

    Methods inherited from 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, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, 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, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, 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, lookupAll, managedProperty, 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, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, 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 inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.css.Styleable

    getStyleableNode
  • Property Details

    • mediaEngine

      public abstract javafx.beans.property.ObjectProperty<MediaEngine> mediaEngineProperty
      Attach the media engine that could be a MediaPlayer or MediaRecorder. A specific MediaView is created for the given media engine, depending on whenever the application is running on desktop/mobile or web via the JPro server.
      See Also:
    • preserveRatio

      public abstract javafx.beans.property.BooleanProperty preserveRatioProperty
      Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the view. 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 true.
      See Also:
    • fitWidth

      public abstract javafx.beans.property.DoubleProperty fitWidthProperty
      Determines the width of the bounding box within which the source media is resized as necessary to fit. If value < 0, than the width of the bounding box will match the width of the parent container node.

      See preserveRatio for information on interaction between media views fitWidth, fitHeight and preserveRatio attributes.

      See Also:
    • fitHeight

      public abstract javafx.beans.property.DoubleProperty fitHeightProperty
      Determines the height of the bounding box within which the source media is resized as necessary to fit. If value < 0, than the height of the bounding box will match the height of the parent container node.

      See preserveRatio for information on interaction between media views fitWidth, fitHeight and preserveRatio attributes.

      See Also:
  • Field Details

    • DEFAULT_STYLE_CLASS

      public static final String DEFAULT_STYLE_CLASS
      See Also:
    • mediaEngine

      protected javafx.beans.property.ObjectProperty<MediaEngine> mediaEngine
    • preserveRatio

      protected javafx.beans.property.BooleanProperty preserveRatio
    • fitWidth

      protected javafx.beans.property.DoubleProperty fitWidth
    • fitHeight

      protected javafx.beans.property.DoubleProperty fitHeight
  • Constructor Details

    • MediaView

      public MediaView()
  • Method Details

    • create

      public static MediaView create(javafx.stage.Stage stage)
      Creates a media view. If the application is running in a browser via JPro server, then a web version of MediaView is returned. If the application is not running inside the browser than a desktop/mobile version of the MediaView is returned.
      Parameters:
      stage - the application stage
      Returns:
      a MediaView object.
    • create

      public static MediaView create(MediaPlayer mediaPlayer)
      Creates a media view for the given media player. If the application is running in a browser via JPro server, then a web version of MediaView is returned. If the application is not running inside the browser than a desktop/mobile version of the MediaView is returned.
      Parameters:
      mediaPlayer - the media player
      Returns:
      a MediaView object.
    • create

      public static MediaView create(MediaRecorder mediaRecorder)
      Creates a media view for the given media recorder. If the application is running in a browser via JPro server, then a web version of MediaView is returned. If the application is not running inside the browser than a desktop/mobile version of the MediaView is returned.
      Parameters:
      mediaRecorder - the media recorder
      Returns:
      a MediaView object.
    • getMediaEngine

      public final MediaEngine getMediaEngine()
      Return the current media engine.
      Returns:
      the current media engine
    • setMediaEngine

      public final void setMediaEngine(MediaEngine value)
      Sets the current media engine, like a MediaPlayer or a MediaRecorder.
      Parameters:
      value - a MediaEngine implementation object, like a MediaPlayer or MediaRecorder
    • mediaEngineProperty

      public abstract javafx.beans.property.ObjectProperty<MediaEngine> mediaEngineProperty()
      Attach the media engine that could be a MediaPlayer or MediaRecorder. A specific MediaView is created for the given media engine, depending on whenever the application is running on desktop/mobile or web via the JPro server.
      Returns:
      the mediaEngine property
      See Also:
    • isPreserveRatio

      public final boolean isPreserveRatio()
      Returns whether the media aspect ratio is preserved when scaling.
      Returns:
      whether the media aspect ratio is preserved.
    • setPreserveRatio

      public final void setPreserveRatio(boolean value)
      Sets whether to preserve the media aspect ratio when scaling.
      Parameters:
      value - whether to preserve the media aspect ratio.
    • preserveRatioProperty

      public abstract javafx.beans.property.BooleanProperty preserveRatioProperty()
      Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the view. 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 true.
      Returns:
      the preserveRatio property
      See Also:
    • getFitWidth

      public final double getFitWidth()
      Retrieves the width of the bounding box of the resized media. Default value is -1.0.
      Returns:
      the height of the resized media.
    • setFitWidth

      public final void setFitWidth(double value)
      Sets the width of the bounding box of the resized media. If value < 0, than the width of the bounding box will match the width of the parent container node.
      Parameters:
      value - the width of the resized media.
    • fitWidthProperty

      public abstract javafx.beans.property.DoubleProperty fitWidthProperty()
      Determines the width of the bounding box within which the source media is resized as necessary to fit. If value < 0, than the width of the bounding box will match the width of the parent container node.

      See preserveRatio for information on interaction between media views fitWidth, fitHeight and preserveRatio attributes.

      Returns:
      the fitWidth property
      See Also:
    • getFitHeight

      public final double getFitHeight()
      Retrieves the height of the bounding box of the resized media. Default value is -1.0.
      Returns:
      the height of the resized media.
    • setFitHeight

      public final void setFitHeight(double value)
      Sets the height of the bounding box of the resized media. If value < 0, than the height of the bounding box will match the height of the parent container node.
      Parameters:
      value - the height of the resized media.
    • fitHeightProperty

      public abstract javafx.beans.property.DoubleProperty fitHeightProperty()
      Determines the height of the bounding box within which the source media is resized as necessary to fit. If value < 0, than the height of the bounding box will match the height of the parent container node.

      See preserveRatio for information on interaction between media views fitWidth, fitHeight and preserveRatio attributes.

      Returns:
      the fitHeight property
      See Also:
    • layoutChildren

      protected void layoutChildren()
      Overrides:
      layoutChildren in class javafx.scene.Parent