Top Description Inners Fields Constructors Methods
javafx.scene.media

public Class MediaView

extends AbstractNode
Class Inheritance
Imports
com.sun.javafx.PlatformUtil, com.sun.javafx.geom.BaseBounds, com.sun.javafx.geom.transform.Affine3D, .BaseTransform, com.sun.javafx.scene.DirtyBits, .AbstractNode, .NodeHelper, com.sun.javafx.scene.media.MediaViewHelper, com.sun.javafx.sg.prism.MediaFrameTracker, .NGNode, com.sun.javafx.tk.Toolkit, com.sun.media.jfxmedia.control.MediaPlayerOverlay, javafx.application.Platform, javafx.beans.InvalidationListener, .Observable, javafx.beans.property.*, javafx.beans.value.ChangeListener, .ObservableObjectValue, javafx.collections.ObservableMap, javafx.event.EventHandler, javafx.geometry.NodeOrientation, .Rectangle2D, javafx.scene.Node, .Parent

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);
}
The foregoing code will display the video as:

Hello Media
Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
MediaView.MediaErrorInvalidationListener

Inner class used to convert a MediaPlayer error into a Bean event.

private class

Field Summary

Modifier and TypeField and Description
private int
private VideoFrameRateListener
decodedFrameRateListener

Listener for decoded frame rate.

private static final String
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
private ObjectProperty<EventHandler<MediaErrorEvent>>
onError

Event handler to be invoked whenever an error occurs on this MediaView.

private ChangeListener<Number>
private ChangeListener<Parent>
private BooleanProperty
preserveRatio

Whether to preserve the aspect ratio (width / height) of the media when scaling it to fit the node.

private boolean
private int
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<Boolean>
private static final String
VIDEO_FRAME_RATE_PROPERTY_NAME

The name of the property in the ObservableMap returned by 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.

Constructor Summary

AccessConstructor and Description
public
MediaView()

Creates a MediaView instance with no associated MediaPlayer.

public
MediaView(MediaPlayer
the MediaPlayer the playback of which is to be viewed via this class.
mediaPlayer
)

Creates a MediaView instance associated with the specified MediaPlayer.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
_mediaPlayerOnReady()

Called by MediaPlayer when it becomes ready

private static Affine3D
private void
private VideoFrameRateListener
createVideoFrameRateListener()

Creates a decoded frame rate listener.

private boolean
private boolean
doComputeContains(double localX, double localY)

private BaseBounds
private NGNode
private void
private void
public final DoubleProperty
public final DoubleProperty
public final double

Returns:

the height of the resized media.
getFitHeight
()

Retrieves the height of the bounding box of the resized media.

public final double

Returns:

the height of the resized media.
getFitWidth
()

Retrieves the width of the bounding box of the resized media.

public final MediaPlayer

Returns:

the associated MediaPlayer.
getMediaPlayer
()

Retrieves the MediaPlayer whose output is being handled by this view.

private MediaView

Returns:

reference to MediaView
getMediaView
()

public final EventHandler<MediaErrorEvent>

Returns:

the error event handler.
getOnError
()

Retrieves the error event handler.

public final Rectangle2D

Returns:

the rectangular viewport.
getViewport
()

Retrieves the rectangular viewport into the media frame.

public final double

Returns:

the x coordinate of the origin of the view.
getX
()

Retrieves the x coordinate of the MediaView origin.

public final double

Returns:

the y coordinate of the origin of the view.
getY
()

Retrieves the y coordinate of the MediaView origin.

public final boolean

Returns:

whether the media aspect ratio is preserved.
isPreserveRatio
()

Returns whether the media aspect ratio is preserved when scaling.

public final boolean

Returns:

whether to smooth the media
isSmooth
()

Returns whether to smooth the media when scaling.

public final ObjectProperty<MediaPlayer>
pack-priv void
pack-priv void
pack-priv void
public final ObjectProperty<EventHandler<MediaErrorEvent>>
pack-priv int

Returns:

number of frames that have been submitted for rendering
perfGetDecodedFrameCount
()

pack-priv int

Returns:

number of frames that have been rendered
perfGetRenderedFrameCount
()

pack-priv void
public final BooleanProperty
public final void
setFitHeight(double
the height of the resized media.
value
)

Sets the height of the bounding box of the resized media.

public final void
setFitWidth(double
the width of the resized media.
value
)

Sets the width of the bounding box of the resized media.

public final void
setMediaPlayer(MediaPlayer
the associated MediaPlayer.
value
)

Sets the MediaPlayer whose output will be handled by this view.

public final void
setOnError(EventHandler<MediaErrorEvent>
the error event handler.
value
)

Sets the error event handler.

public final void
setPreserveRatio(boolean
whether to preserve the media aspect ratio.
value
)

Sets whether to preserve the media aspect ratio when scaling.

public final void
setSmooth(boolean
whether to smooth the media.
value
)

Sets whether to smooth the media when scaling.

public final void
setViewport(Rectangle2D
the rectangular viewport.
value
)

Sets the rectangular viewport into the media frame.

public final void
setX(double
the x coordinate of the origin of the view.
value
)

Sets the x coordinate of the MediaView origin.

public final void
setY(double
the y coordinate of the origin of the view.
value
)

Sets the y coordinate of the MediaView origin.

public final BooleanProperty
private void
private synchronized void
private synchronized void
private synchronized void
private void
private synchronized void
private synchronized void
private synchronized void
private synchronized void
pack-priv void
public final ObjectProperty<Rectangle2D>
public final DoubleProperty
public final DoubleProperty

Field Detail

decodedFrameCountback to summary
private int decodedFrameCount
decodedFrameRateListenerback to summary
private VideoFrameRateListener decodedFrameRateListener

Listener for decoded frame rate.

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS
errorListenerback to summary
private InvalidationListener errorListener

Listener which converts MediaPlayer errors to events.

fitHeightback to summary
private DoubleProperty fitHeight

Determines the height of the bounding box within which the source media is resized as necessary to fit. If 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.

fitWidthback to summary
private DoubleProperty fitWidth

Determines the width of the bounding box within which the source media is resized as necessary to fit. If 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.

mediaDimensionListenerback to summary
private InvalidationListener mediaDimensionListener

Listener which causes the geometry to be updated when the media dimension changes.

mediaPlayerback to summary
private ObjectProperty<MediaPlayer> mediaPlayer

The 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.

See Also
MediaException, MediaPlayer
mediaPlayerOverlayback to summary
private MediaPlayerOverlay mediaPlayerOverlay
onErrorback to summary
private ObjectProperty<EventHandler<MediaErrorEvent>> onError

Event handler to be invoked whenever an error occurs on this MediaView.

See Also
MediaErrorEvent
opacityListenerback to summary
private ChangeListener<Number> opacityListener
parentListenerback to summary
private ChangeListener<Parent> parentListener
preserveRatioback to summary
private BooleanProperty preserveRatio

Whether 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 is true.

registerVideoFrameRateListenerback to summary
private boolean registerVideoFrameRateListener
renderedFrameCountback to summary
private int renderedFrameCount
smoothback to summary
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. If set to false a faster but lesser quality filtering will be used. The default value depends on platform configuration.

treeVisibleListenerback to summary
private ChangeListener<Boolean> treeVisibleListener
VIDEO_FRAME_RATE_PROPERTY_NAMEback to summary
private static final String VIDEO_FRAME_RATE_PROPERTY_NAME

The name of the property in the ObservableMap returned by getProperties(). This value must also be defined as a JVM command line definition for the frame rate to be added to the properties.

viewportback to summary
private ObjectProperty<Rectangle2D> viewport

Specifies 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. Setting viewport to null will clear the viewport.

xback to summary
private DoubleProperty x

Defines the current x coordinate of the MediaView origin.

yback to summary
private DoubleProperty y

Defines the current y coordinate of the MediaView origin.

Constructor Detail

MediaViewback to summary
public MediaView()

Creates a MediaView instance with no associated MediaPlayer.

MediaViewback to summary
public MediaView(MediaPlayer mediaPlayer)

Creates a MediaView instance associated with the specified MediaPlayer. Equivalent to


MediaPlayer player; // initialization omitted
MediaView view = new MediaView();
view.setMediaPlayer(player);
Parameters
mediaPlayer:MediaPlayer

the MediaPlayer the playback of which is to be viewed via this class.

Method Detail

_mediaPlayerOnReadyback to summary
pack-priv void _mediaPlayerOnReady()

Called by MediaPlayer when it becomes ready

calculateNodeToSceneTransformback to summary
private static Affine3D calculateNodeToSceneTransform(Node node)
createListenersback to summary
private void createListeners()
createVideoFrameRateListenerback to summary
private VideoFrameRateListener createVideoFrameRateListener()

Creates a decoded frame rate listener. Will return null if the security manager does not permit retrieve system properties or if VIDEO_FRAME_RATE_PROPERTY_NAME is not set to "true."

determineVisibilityback to summary
private boolean determineVisibility()
doComputeContainsback to summary
private boolean doComputeContains(double localX, double localY)
doComputeGeomBoundsback to summary
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)
doCreatePeerback to summary
private NGNode doCreatePeer()
doTransformsChangedback to summary
private void doTransformsChanged()

Hides javafx.scene.Node.doTransformsChanged.

doUpdatePeerback to summary
private void doUpdatePeer()

Hides javafx.scene.Node.doUpdatePeer.

fitHeightPropertyback to summary
public final DoubleProperty fitHeightProperty()
fitWidthPropertyback to summary
public final DoubleProperty fitWidthProperty()
getFitHeightback to summary
public final double getFitHeight()

Retrieves the height of the bounding box of the resized media.

Returns:double

the height of the resized media.

getFitWidthback to summary
public final double getFitWidth()

Retrieves the width of the bounding box of the resized media.

Returns:double

the height of the resized media.

getMediaPlayerback to summary
public final MediaPlayer getMediaPlayer()

Retrieves the MediaPlayer whose output is being handled by this view.

Returns:MediaPlayer

the associated MediaPlayer.

getMediaViewback to summary
private MediaView getMediaView()
Returns:MediaView

reference to MediaView

getOnErrorback to summary
public final EventHandler<MediaErrorEvent> getOnError()

Retrieves the error event handler.

Returns:EventHandler<MediaErrorEvent>

the error event handler.

getViewportback to summary
public final Rectangle2D getViewport()

Retrieves the rectangular viewport into the media frame.

Returns:Rectangle2D

the rectangular viewport.

getXback to summary
public final double getX()

Retrieves the x coordinate of the MediaView origin.

Returns:double

the x coordinate of the origin of the view.

getYback to summary
public final double getY()

Retrieves the y coordinate of the MediaView origin.

Returns:double

the y coordinate of the origin of the view.

isPreserveRatioback to summary
public final boolean isPreserveRatio()

Returns whether the media aspect ratio is preserved when scaling.

Returns:boolean

whether the media aspect ratio is preserved.

isSmoothback to summary
public final boolean isSmooth()

Returns whether to smooth the media when scaling.

Returns:boolean

whether to smooth the media

mediaPlayerPropertyback to summary
public final ObjectProperty<MediaPlayer> mediaPlayerProperty()
notifyMediaChangeback to summary
pack-priv void notifyMediaChange()
notifyMediaFrameUpdatedback to summary
pack-priv void notifyMediaFrameUpdated()
notifyMediaSizeChangeback to summary
pack-priv void notifyMediaSizeChange()
onErrorPropertyback to summary
public final ObjectProperty<EventHandler<MediaErrorEvent>> onErrorProperty()
perfGetDecodedFrameCountback to summary
pack-priv int perfGetDecodedFrameCount()
Returns:int

number of frames that have been submitted for rendering

perfGetRenderedFrameCountback to summary
pack-priv int perfGetRenderedFrameCount()
Returns:int

number of frames that have been rendered

perfResetback to summary
pack-priv void perfReset()
preserveRatioPropertyback to summary
public final BooleanProperty preserveRatioProperty()
setFitHeightback to summary
public final void setFitHeight(double value)

Sets the height of the bounding box of the resized media.

Parameters
value:double

the height of the resized media.

setFitWidthback to summary
public final void setFitWidth(double value)

Sets the width of the bounding box of the resized media.

Parameters
value:double

the width of the resized media.

setMediaPlayerback to summary
public final void setMediaPlayer(MediaPlayer value)

Sets the MediaPlayer whose output will be handled by this view.

Parameters
value:MediaPlayer

the associated MediaPlayer.

setOnErrorback to summary
public final void setOnError(EventHandler<MediaErrorEvent> value)

Sets the error event handler.

Parameters
value:EventHandler<MediaErrorEvent>

the error event handler.

setPreserveRatioback to summary
public final void setPreserveRatio(boolean value)

Sets whether to preserve the media aspect ratio when scaling.

Parameters
value:boolean

whether to preserve the media aspect ratio.

setSmoothback to summary
public final void setSmooth(boolean value)

Sets whether to smooth the media when scaling.

Parameters
value:boolean

whether to smooth the media.

setViewportback to summary
public final void setViewport(Rectangle2D value)

Sets the rectangular viewport into the media frame.

Parameters
value:Rectangle2D

the rectangular viewport.

setXback to summary
public final void setX(double value)

Sets the x coordinate of the MediaView origin.

Parameters
value:double

the x coordinate of the origin of the view.

setYback to summary
public final void setY(double value)

Sets the y coordinate of the MediaView origin.

Parameters
value:double

the y coordinate of the origin of the view.

smoothPropertyback to summary
public final BooleanProperty smoothProperty()
updateMediaPlayerOverlayback to summary
private void updateMediaPlayerOverlay()
updateOverlayHeightback to summary
private synchronized void updateOverlayHeight()
updateOverlayOpacityback to summary
private synchronized void updateOverlayOpacity()
updateOverlayPreserveRatioback to summary
private synchronized void updateOverlayPreserveRatio()
updateOverlayTransformback to summary
private void updateOverlayTransform()
updateOverlayVisibilityback to summary
private synchronized void updateOverlayVisibility()
updateOverlayWidthback to summary
private synchronized void updateOverlayWidth()
updateOverlayXback to summary
private synchronized void updateOverlayX()
updateOverlayYback to summary
private synchronized void updateOverlayY()
updateViewportback to summary
pack-priv void updateViewport()
viewportPropertyback to summary
public final ObjectProperty<Rectangle2D> viewportProperty()
xPropertyback to summary
public final DoubleProperty xProperty()
yPropertyback to summary
public final DoubleProperty yProperty()
javafx.scene.media back to summary

private Class MediaView.MediaErrorInvalidationListener

extends Object
implements InvalidationListener
Class Inheritance
All Implemented Interfaces
javafx.beans.InvalidationListener

Inner class used to convert a MediaPlayer error into a Bean event.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
invalidated(Observable
The Observable that became invalid
value
)

Implements javafx.beans.InvalidationListener.invalidated.

This method needs to be provided by an implementation of InvalidationListener.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MediaErrorInvalidationListenerback to summary
private MediaErrorInvalidationListener()

Method Detail

invalidatedback to summary
public void invalidated(Observable value)

Implements javafx.beans.InvalidationListener.invalidated.

Doc from javafx.beans.InvalidationListener.invalidated.

This method needs to be provided by an implementation of InvalidationListener. It is called if an Observable becomes invalid.

In general, it is considered bad practice to modify the observed value in this method.

Parameters
value:Observable

The Observable that became invalid

Annotations
@Override
javafx.scene.media back to summary

private Class MediaView.MediaViewFrameTracker

extends Object
implements MediaFrameTracker
Class Inheritance
All Implemented Interfaces
com.sun.javafx.sg.prism.MediaFrameTracker

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MediaViewFrameTrackerback to summary
private MediaViewFrameTracker()

Method Detail

incrementDecodedFrameCountback to summary
public void incrementDecodedFrameCount(int count)

Implements com.sun.javafx.sg.prism.MediaFrameTracker.incrementDecodedFrameCount.

Annotations
@Override
incrementRenderedFrameCountback to summary
public void incrementRenderedFrameCount(int count)

Implements com.sun.javafx.sg.prism.MediaFrameTracker.incrementRenderedFrameCount.

Annotations
@Override