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:
Type | Property and Description |
---|---|
DoubleProperty |
fitHeight
Determines the height of the bounding box within which the source media is
resized as necessary to fit.
|
DoubleProperty |
fitWidth
Determines the width of the bounding box within which the source media is
resized as necessary to fit.
|
<any> |
mediaPlayer
The
mediaPlayer whose output will be handled by this view. |
<any> |
onError
Event handler to be invoked whenever an error occurs on this
MediaView . |
BooleanProperty |
preserveRatio
Whether to preserve the aspect ratio (width / height) of the media when
scaling it to fit the node.
|
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. |
<any> |
viewport
Specifies a rectangular viewport into the media frame.
|
DoubleProperty |
x
Defines the current x coordinate of the
MediaView origin. |
DoubleProperty |
y
Defines the current y coordinate of the
MediaView origin. |
Modifier and Type | Class and Description |
---|---|
private class |
MediaView.MediaErrorInvalidationListener
Inner class used to convert a
MediaPlayer error into a
Bean event. |
private class |
MediaView.MediaViewFrameTracker |
Modifier and Type | Field and Description |
---|---|
private int |
decodedFrameCount |
private com.sun.media.jfxmedia.events.VideoFrameRateListener |
decodedFrameRateListener
Listener for decoded frame rate.
|
private static java.lang.String |
DEFAULT_STYLE_CLASS |
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 <any> |
mediaPlayer
The
mediaPlayer whose output will be handled by this view. |
private MediaPlayerOverlay |
mediaPlayerOverlay
Media Player Overlay support
|
private <any> |
onError
Event handler to be invoked whenever an error occurs on this
MediaView . |
private <any> |
opacityListener |
private <any> |
parentListener |
private BooleanProperty |
preserveRatio
Whether to preserve the aspect ratio (width / height) of the media when
scaling it to fit the node.
|
private boolean |
registerVideoFrameRateListener |
private int |
renderedFrameCount |
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 <any> |
treeVisibleListener |
private static java.lang.String |
VIDEO_FRAME_RATE_PROPERTY_NAME
The name of the property in the
ObservableMap returned by
#getProperties() . |
private <any> |
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 and Description |
---|
MediaView()
Creates a
MediaView instance with no associated
MediaPlayer . |
MediaView(MediaPlayer mediaPlayer)
Creates a
MediaView instance associated with the specified
MediaPlayer . |
Modifier and Type | Method and Description |
---|---|
(package private) void |
_mediaPlayerOnReady()
Called by MediaPlayer when it becomes ready
|
private static Affine3D |
calculateNodeToSceneTransform(Node node) |
private void |
createListeners() |
private com.sun.media.jfxmedia.events.VideoFrameRateListener |
createVideoFrameRateListener()
Creates a decoded frame rate listener.
|
private boolean |
determineVisibility() |
private boolean |
doComputeContains(double localX,
double localY) |
private BaseBounds |
doComputeGeomBounds(BaseBounds bounds,
BaseTransform tx) |
private NGNode |
doCreatePeer() |
private void |
doTransformsChanged() |
private void |
doUpdatePeer() |
DoubleProperty |
fitHeightProperty()
Determines the height of the bounding box within which the source media is
resized as necessary to fit.
|
DoubleProperty |
fitWidthProperty()
Determines the width of the bounding box within which the source media is
resized as necessary to fit.
|
double |
getFitHeight()
Retrieves the height of the bounding box of the resized media.
|
double |
getFitWidth()
Retrieves the width of the bounding box of the resized media.
|
MediaPlayer |
getMediaPlayer()
Retrieves the
MediaPlayer whose output is being handled by
this view. |
private MediaView |
getMediaView() |
<any> |
getOnError()
Retrieves the error event handler.
|
Rectangle2D |
getViewport()
Retrieves the rectangular viewport into the media frame.
|
double |
getX()
Retrieves the x coordinate of the
MediaView origin. |
double |
getY()
Retrieves the y coordinate of the
MediaView origin. |
boolean |
isPreserveRatio()
Returns whether the media aspect ratio is preserved when scaling.
|
boolean |
isSmooth()
Returns whether to smooth the media when scaling.
|
<any> |
mediaPlayerProperty()
The
mediaPlayer whose output will be handled by this view. |
(package private) void |
notifyMediaChange() |
(package private) void |
notifyMediaFrameUpdated() |
(package private) void |
notifyMediaSizeChange() |
<any> |
onErrorProperty()
Event handler to be invoked whenever an error occurs on this
MediaView . |
(package private) int |
perfGetDecodedFrameCount() |
(package private) int |
perfGetRenderedFrameCount() |
(package private) void |
perfReset() |
BooleanProperty |
preserveRatioProperty()
Whether to preserve the aspect ratio (width / height) of the media when
scaling it to fit the node.
|
void |
setFitHeight(double value)
Sets the height of the bounding box of the resized media.
|
void |
setFitWidth(double value)
Sets the width of the bounding box of the resized media.
|
void |
setMediaPlayer(MediaPlayer value)
Sets the
MediaPlayer whose output will be handled by this view. |
void |
setOnError(<any> value)
Sets the error event handler.
|
void |
setPreserveRatio(boolean value)
Sets whether to preserve the media aspect ratio when scaling.
|
void |
setSmooth(boolean value)
Sets whether to smooth the media when scaling.
|
void |
setViewport(Rectangle2D value)
Sets the rectangular viewport into the media frame.
|
void |
setX(double value)
Sets the x coordinate of the
MediaView origin. |
void |
setY(double value)
Sets the y coordinate of the
MediaView origin. |
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. |
private void |
updateMediaPlayerOverlay() |
private void |
updateOverlayHeight() |
private void |
updateOverlayOpacity() |
private void |
updateOverlayPreserveRatio() |
private void |
updateOverlayTransform() |
private void |
updateOverlayVisibility() |
private void |
updateOverlayWidth() |
private void |
updateOverlayX() |
private void |
updateOverlayY() |
(package private) void |
updateViewport() |
<any> |
viewportProperty()
Specifies a rectangular viewport into the media frame.
|
DoubleProperty |
xProperty()
Defines the current x coordinate of the
MediaView origin. |
DoubleProperty |
yProperty()
Defines the current y coordinate of the
MediaView origin. |
public final <any> 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.getMediaPlayer()
,
setMediaPlayer(MediaPlayer)
public final <any> onErrorProperty
MediaView
.getOnError()
,
#setOnError()
public final BooleanProperty preserveRatioProperty
true
.isPreserveRatio()
,
setPreserveRatio(boolean)
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.isSmooth()
,
setSmooth(boolean)
public final DoubleProperty xProperty
MediaView
origin.getX()
,
setX(double)
public final DoubleProperty yProperty
MediaView
origin.getY()
,
setY(double)
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.
getFitWidth()
,
setFitWidth(double)
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.
getFitHeight()
,
setFitHeight(double)
public final <any> viewportProperty
viewport
to null will clear the viewport.getViewport()
,
setViewport(Rectangle2D)
private static final java.lang.String VIDEO_FRAME_RATE_PROPERTY_NAME
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.private static final java.lang.String DEFAULT_STYLE_CLASS
private InvalidationListener errorListener
MediaPlayer
errors to events.private InvalidationListener mediaDimensionListener
private com.sun.media.jfxmedia.events.VideoFrameRateListener decodedFrameRateListener
private boolean registerVideoFrameRateListener
private MediaPlayerOverlay mediaPlayerOverlay
private <any> parentListener
private <any> treeVisibleListener
private <any> opacityListener
private <any> mediaPlayer
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.MediaException
,
MediaPlayer
private <any> onError
MediaView
.MediaErrorEvent
private BooleanProperty preserveRatio
true
.private BooleanProperty smooth
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.private DoubleProperty x
MediaView
origin.private DoubleProperty y
MediaView
origin.private DoubleProperty fitWidth
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.
private DoubleProperty fitHeight
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.
private <any> viewport
viewport
to null will clear the viewport.private int decodedFrameCount
private int renderedFrameCount
public MediaView()
MediaView
instance with no associated
MediaPlayer
.public MediaView(MediaPlayer mediaPlayer)
MediaView
instance associated with the specified
MediaPlayer
. Equivalent to
MediaPlayer player; // initialization omitted
MediaView view = new MediaView();
view.setMediaPlayer(player);
mediaPlayer
- the MediaPlayer
the playback of which is to be
viewed via this class.private com.sun.media.jfxmedia.events.VideoFrameRateListener createVideoFrameRateListener()
null
if
the security manager does not permit retrieve system properties or if
VIDEO_FRAME_RATE_PROPERTY_NAME is not set to "true."private void createListeners()
private boolean determineVisibility()
private void updateOverlayVisibility()
private void updateOverlayOpacity()
private void updateOverlayX()
private void updateOverlayY()
private void updateOverlayWidth()
private void updateOverlayHeight()
private void updateOverlayPreserveRatio()
private static Affine3D calculateNodeToSceneTransform(Node node)
private void updateOverlayTransform()
private void updateMediaPlayerOverlay()
private void doTransformsChanged()
private MediaView getMediaView()
public final void setMediaPlayer(MediaPlayer value)
MediaPlayer
whose output will be handled by this view.value
- the associated MediaPlayer
.public final MediaPlayer getMediaPlayer()
MediaPlayer
whose output is being handled by
this view.MediaPlayer
.public final <any> 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.getMediaPlayer()
,
setMediaPlayer(MediaPlayer)
public final void setOnError(<any> value)
value
- the error event handler.public final <any> getOnError()
public final <any> onErrorProperty()
MediaView
.getOnError()
,
#setOnError()
public final void setPreserveRatio(boolean value)
value
- whether to preserve the media aspect ratio.public final boolean isPreserveRatio()
public final BooleanProperty preserveRatioProperty()
true
.isPreserveRatio()
,
setPreserveRatio(boolean)
public final void setSmooth(boolean value)
value
- whether to smooth the media.public final boolean isSmooth()
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.isSmooth()
,
setSmooth(boolean)
public final void setX(double value)
MediaView
origin.value
- the x coordinate of the origin of the view.public final double getX()
MediaView
origin.public final DoubleProperty xProperty()
MediaView
origin.getX()
,
setX(double)
public final void setY(double value)
MediaView
origin.value
- the y coordinate of the origin of the view.public final double getY()
MediaView
origin.public final DoubleProperty yProperty()
MediaView
origin.getY()
,
setY(double)
public final void setFitWidth(double value)
value
- the width of the resized media.public final double getFitWidth()
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.
getFitWidth()
,
setFitWidth(double)
public final void setFitHeight(double value)
value
- the height of the resized media.public final double getFitHeight()
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.
getFitHeight()
,
setFitHeight(double)
public final void setViewport(Rectangle2D value)
value
- the rectangular viewport.public final Rectangle2D getViewport()
public final <any> viewportProperty()
viewport
to null will clear the viewport.getViewport()
,
setViewport(Rectangle2D)
void notifyMediaChange()
void notifyMediaSizeChange()
void notifyMediaFrameUpdated()
private NGNode doCreatePeer()
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)
private boolean doComputeContains(double localX, double localY)
void updateViewport()
private void doUpdatePeer()
void perfReset()
int perfGetDecodedFrameCount()
int perfGetRenderedFrameCount()
void _mediaPlayerOnReady()