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
PropertiesTypePropertyDescriptionabstract javafx.beans.property.DoublePropertyDetermines the height of the bounding box within which the source media is resized as necessary to fit.abstract javafx.beans.property.DoublePropertyDetermines 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 aMediaPlayerorMediaRecorder.abstract javafx.beans.property.BooleanPropertyWhether 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, widthProperties inherited from class javafx.scene.Parent
needsLayoutProperties 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
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected javafx.beans.property.DoublePropertyprotected javafx.beans.property.DoublePropertyprotected javafx.beans.property.ObjectProperty<MediaEngine> protected javafx.beans.property.BooleanPropertyFields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZEFields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MediaViewcreate(javafx.stage.Stage stage) Creates a media view.static MediaViewcreate(MediaPlayer mediaPlayer) Creates a media view for the given media player.static MediaViewcreate(MediaRecorder mediaRecorder) Creates a media view for the given media recorder.abstract javafx.beans.property.DoublePropertyDetermines the height of the bounding box within which the source media is resized as necessary to fit.abstract javafx.beans.property.DoublePropertyDetermines the width of the bounding box within which the source media is resized as necessary to fit.final doubleRetrieves the height of the bounding box of the resized media.final doubleRetrieves the width of the bounding box of the resized media.final MediaEngineReturn the current media engine.final booleanReturns whether the media aspect ratio is preserved when scaling.protected voidabstract javafx.beans.property.ObjectProperty<MediaEngine> Attach the media engine that could be aMediaPlayerorMediaRecorder.abstract javafx.beans.property.BooleanPropertyWhether to preserve the aspect ratio (width / height) of the media when scaling it to fit the view.final voidsetFitHeight(double value) Sets the height of the bounding box of the resized media.final voidsetFitWidth(double value) Sets the width of the bounding box of the resized media.final voidsetMediaEngine(MediaEngine value) Sets the current media engine, like aMediaPlayeror aMediaRecorder.final voidsetPreserveRatio(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, widthPropertyMethods inherited from class javafx.scene.Parent
getBaselineOffset, getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, queryAccessibleAttribute, requestLayout, requestParentLayout, setNeedsLayout, updateBoundsMethods 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, visiblePropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
mediaEngine
Attach the media engine that could be aMediaPlayerorMediaRecorder. A specificMediaViewis 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 preserveRatioPropertyWhether 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 istrue.- See Also:
-
fitWidth
public abstract javafx.beans.property.DoubleProperty fitWidthPropertyDetermines the width of the bounding box within which the source media is resized as necessary to fit. Ifvalue < 0, than the width of the bounding box will match the width of the parent container node.See
preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- See Also:
-
fitHeight
public abstract javafx.beans.property.DoubleProperty fitHeightPropertyDetermines the height of the bounding box within which the source media is resized as necessary to fit. Ifvalue < 0, than the height of the bounding box will match the height of the parent container node.See
preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- See Also:
-
-
Field Details
-
DEFAULT_STYLE_CLASS
- See Also:
-
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
Creates a media view. If the application is running in a browser via JPro server, then a web version ofMediaViewis returned. If the application is not running inside the browser than a desktop/mobile version of theMediaViewis returned.- Parameters:
stage- the application stage- Returns:
- a
MediaViewobject.
-
create
Creates a media view for the given media player. If the application is running in a browser via JPro server, then a web version ofMediaViewis returned. If the application is not running inside the browser than a desktop/mobile version of theMediaViewis returned.- Parameters:
mediaPlayer- the media player- Returns:
- a
MediaViewobject.
-
create
Creates a media view for the given media recorder. If the application is running in a browser via JPro server, then a web version ofMediaViewis returned. If the application is not running inside the browser than a desktop/mobile version of theMediaViewis returned.- Parameters:
mediaRecorder- the media recorder- Returns:
- a
MediaViewobject.
-
getMediaEngine
Return the current media engine.- Returns:
- the current media engine
-
setMediaEngine
Sets the current media engine, like aMediaPlayeror aMediaRecorder.- Parameters:
value- aMediaEngineimplementation object, like aMediaPlayerorMediaRecorder
-
mediaEngineProperty
Attach the media engine that could be aMediaPlayerorMediaRecorder. A specificMediaViewis created for the given media engine, depending on whenever the application is running on desktop/mobile or web via the JPro server.- Returns:
- the
mediaEngineproperty - 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 istrue.- Returns:
- the
preserveRatioproperty - 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. Ifvalue < 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. Ifvalue < 0, than the width of the bounding box will match the width of the parent container node.See
preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- Returns:
- the
fitWidthproperty - 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. Ifvalue < 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. Ifvalue < 0, than the height of the bounding box will match the height of the parent container node.See
preserveRatiofor information on interaction between media viewsfitWidth,fitHeightandpreserveRatioattributes.- Returns:
- the
fitHeightproperty - See Also:
-
layoutChildren
protected void layoutChildren()- Overrides:
layoutChildrenin classjavafx.scene.Parent
-