Skip to content

ResourcePlayerNode

class ResourcePlayerNode
Extends: Node
Package: dev.joid.lib.ui.node.impl.resource · Module: core · Source: ResourcePlayerNode.java

Plays a video or an animated image in its bounds, with its sound, and controls the playback.

Each player plays its own copy of the resource, made when the node is attached, so two players of the same resource play separately. Before that copy exists, play, pause, stop, restart and seek are kept and applied when the playback starts; getPlayback() and getVideo() return null. The node waits for its resource like a ResourceNode and takes its size the same way.

ReturnsSignatureSummary
ResourcePlayerNodecreate(double x, double y) factoryCreates a player at x, y that takes the size of its resource.
ResourcePlayerNodecreate(double x, double y, double width, double height) factoryCreates a player with a declared size; a size of 0 on an axis follows the ratio of the resource.
ResourcePlayerNode(double x, double y, double width, double height) protectedCalled by a subclass with the same arguments as create.

PropertyTypeDefaultSummary
resource signalResourcenullThe video or animated image to play.
stretch signalStretchTypeStretchType.STRETCHHow the frames fill the bounds.
autoplay signalbooleantrueIf true, the playback starts as soon as the resource is ready; if false, it waits paused on its first frame, an animated image as a video.
loop signalbooleanfalseIf true, the playback starts again at the end instead of ending.
volume signalfloat1FVolume of the sound of a video, from 0 for silence to 1 for the full volume.
audioGroup signalObjectnullGroup of the sound of a video, for the audio bridge to set the volume of several players at once.
location signalPointnone, the sound plays without positionPosition of the sound of a video, whose volume falls with its distance to the position of VideoAudioPlayer.audioListenerPosition; null plays it without position.
referenceDistance signalfloat5, the distance of the video decoderDistance from location within which the sound plays at full volume; null keeps 5.
maxDistance signalfloat50, the distance of the video decoderDistance from location from which the sound is silent; in between, the volume falls as (1 − t)², t going from 0 to 1 between the two distances; null keeps 50.
Inherited from Node (24)

x · y · width · height · position · anchor · anchorX · anchorY · aspectRatio · zindex · zlevel · skeleton · visible · enabled · interactive · cursor · hoverDuration · hoverEquation · hover · overflow · scrollSpeed · scrollbar · label · draggable

ReturnsSignatureSummary
doublegetDuration()Length of the resource, in seconds; 0 before the playback exists.
doublegetProgress()Share of the resource already played, from 0 to 1.
IResourcePlaybackgetPlayback()The playback of the copy that this node plays, or null before the node is attached or when the resource has none.
VideoResourceDecodergetVideo()The video decoder of the copy that this node plays, or null when the resource is not a video or the node is not attached.
booleanisPaused()If true, the playback is paused.
booleanisPlaying()If true, the playback is playing.
ReturnsSignatureSummary
thisplay() fluentStarts the playback, or resumes it after a pause or a stop; onPlay fires on the next frame, once the playback runs.
thisstop() fluentStops the playback, back at the start, and fires onStop.
thispause() fluentPauses a playing resource and fires onPause.
thistoggle() fluentPauses a playing resource, otherwise plays it.
thisrestart() fluentPlays the resource again from the start.
thisseek(double seconds) fluentMoves the playback to this time, in seconds.
ReturnsSignatureSummary
voidupdate() hookMeasures the resource on every frame, so that the node takes its size as soon as it loads.
voiddraw(double mouseX, double mouseY) hookStarts the playback on the first frame, fires the playback events, then draws the current frame.
voiddetach() hookReleases the copy that this node plays and its sound; attaching the node again starts from the beginning.
Inherited from Node (128)

load · render · renderHover · updateScroll · updateScrollX · updateScrollY · append · attach · body · clearChildren · getChild · getChildren · getNodeListAt · getParent · isAttached · getAbsoluteX · getAbsoluteY · getAbsoluteDefaultX · getAbsoluteDefaultY · toDrawX · toDrawY · w · h · dw · dh · mw · mh · aw · ah · ax · ay · getDefaultWidth · getDefaultHeight · removeHover · clearHover · refreshHover · getResolvedCursor · hoverValue · getHoverAnimator · isHovered · handleMousePressed · handleMouseReleased · handleMouseDragged · handleMouseScroll · handleCharTyped · handleKeyPressed · handleKeyReleased · getLastClickTime · getLastClickButton · getLastKey · getLastKeyTime · scrollX · scrollY · scrollTo · beforeScroll · hasOverflowX · hasOverflowY · getOverflowArea · getScrollX · getScrollY · getTargetScrollX · getTargetScrollY · getMaxScrollX · getMaxScrollY · isScrollEndX · isScrollEndY · startDragging · stopDragging · beforeDragStart · beforeDragDrop · isDragging · getDragX · getDragY · isDragged · getDragSource · getDraggedNode · getStartDragX · getStartDragY · getTargetDragX · getTargetDragY · effect · removeEffect · clearEffects · hasEffect · getEffect · layer · clearLayers · animate · removeAnimator · wait · watch · hasListener · isVisibleProperty · isMounted · getIndex · getUi · getHierarchy · getMappedIndex · getTaskList · getShortcutList · toJson · toString · getEventBus · getBodyConsumer · getDefaultX · getDefaultY · getLayoutX · getLayoutY · getShiftX · getShiftY · isStepping · getLastCodepoint · getLoadCount · getRenderTime · remove · self · copy · useStore · addTask · removeTask · addShortcut · removeShortcut · layoutPosition · layoutSize · fit · move · beforeMove · hoverColor

EventListenerSummary
onPlayEventListener<NodeEvent<T>>Adds a listener that runs when the playback starts or resumes.
onPauseEventListener<NodeEvent<T>>Adds a listener that runs when the playback pauses.
onStopEventListener<NodeEvent<T>>Adds a listener that runs when the playback stops, by stop() or at the end of a resource that does not loop.
onEndEventListener<NodeEvent<T>>Adds a listener that runs when a resource that does not loop reaches its end, before onStop.
onProgressEventListener<NodeProgressEvent<T>>Adds a listener that runs on every frame where the progress changes, with the progress and the current time.
Inherited from Node (21)

onUpdate · onDetach · onInit · onRender · onDraw · onMount · onHoverStart · onHover · onHoverEnd · onScroll · onScrollToEnd · onScrollEndReached · onDragStart · onDrag · onDragDrop · onDragSnap · onMove · onChildAppend · onClick · onAnimate · onWatch

ResourcePlayerNode create(double x, double y) factory

Creates a player at x, y that takes the size of its resource.

ResourcePlayerNode create(double x, double y, double width, double height) factory

Creates a player with a declared size; a size of 0 on an axis follows the ratio of the resource.

ResourcePlayerNode(double x, double y, double width, double height) protected

Called by a subclass with the same arguments as create.

  • this resource(Resource resource) fluent
  • this resource(Supplier<Resource> resource) fluent signal
  • Resource getResource()

Default: null

The video or animated image to play. Another resource restarts the playback; the same resource with the same properties keeps it. Throws an IllegalStateException when the node is attached without one.

  • this stretch(StretchType stretch) fluent
  • this stretch(Supplier<StretchType> stretch) fluent signal
  • StretchType getStretch()

Default: StretchType.STRETCH

How the frames fill the bounds.

  • this autoplay(boolean autoplay) fluent
  • this autoplay(Supplier<Boolean> autoplay) fluent signal
  • boolean isAutoplay()

Default: true

If true, the playback starts as soon as the resource is ready; if false, it waits paused on its first frame, an animated image as a video.

  • this loop(boolean loop) fluent
  • this loop(Supplier<Boolean> loop) fluent signal
  • boolean isLoop()

Default: false

If true, the playback starts again at the end instead of ending.

  • this volume(float volume) fluent
  • this volume(Supplier<Float> volume) fluent signal
  • float getVolume()

Default: 1F

Volume of the sound of a video, from 0 for silence to 1 for the full volume.

  • this audioGroup(Object audioGroup) fluent
  • this audioGroup(Supplier<?> audioGroup) fluent signal
  • Object getAudioGroup()

Default: null

Group of the sound of a video, for the audio bridge to set the volume of several players at once.

  • this location(Point location) fluent
  • this location(Supplier<Point> location) fluent signal
  • Point getLocation()

Default: none, the sound plays without position

Position of the sound of a video, whose volume falls with its distance to the position of VideoAudioPlayer.audioListenerPosition; null plays it without position.

  • this referenceDistance(float referenceDistance) fluent
  • this referenceDistance(Supplier<Float> referenceDistance) fluent signal
  • Float getReferenceDistance()

Default: 5, the distance of the video decoder

Distance from location within which the sound plays at full volume; null keeps 5.

  • this maxDistance(float maxDistance) fluent
  • this maxDistance(Supplier<Float> maxDistance) fluent signal
  • Float getMaxDistance()

Default: 50, the distance of the video decoder

Distance from location from which the sound is silent; in between, the volume falls as (1 − t)², t going from 0 to 1 between the two distances; null keeps 50.

double getDuration()

Length of the resource, in seconds; 0 before the playback exists.

double getProgress()

Share of the resource already played, from 0 to 1.

IResourcePlayback getPlayback()

The playback of the copy that this node plays, or null before the node is attached or when the resource has none.

VideoResourceDecoder getVideo()

The video decoder of the copy that this node plays, or null when the resource is not a video or the node is not attached.

boolean isPaused()

If true, the playback is paused.

boolean isPlaying()

If true, the playback is playing.

this play() fluent

Starts the playback, or resumes it after a pause or a stop; onPlay fires on the next frame, once the playback runs. Throws an IllegalStateException when the resource has no playback, such as a still image.

this stop() fluent

Stops the playback, back at the start, and fires onStop.

this pause() fluent

Pauses a playing resource and fires onPause.

this toggle() fluent

Pauses a playing resource, otherwise plays it.

this restart() fluent

Plays the resource again from the start.

this seek(double seconds) fluent

Moves the playback to this time, in seconds. A stopped resource pauses at that time and shows its frame.

void update() hook

Measures the resource on every frame, so that the node takes its size as soon as it loads.

void draw(double mouseX, double mouseY) hook

Starts the playback on the first frame, fires the playback events, then draws the current frame.

void detach() hook

Releases the copy that this node plays and its sound; attaching the node again starts from the beginning.

this onPlay(EventListener<NodeEvent<T>> listener) fluent

Adds a listener that runs when the playback starts or resumes.

this onPause(EventListener<NodeEvent<T>> listener) fluent

Adds a listener that runs when the playback pauses.

this onStop(EventListener<NodeEvent<T>> listener) fluent

Adds a listener that runs when the playback stops, by stop() or at the end of a resource that does not loop.

this onEnd(EventListener<NodeEvent<T>> listener) fluent

Adds a listener that runs when a resource that does not loop reaches its end, before onStop.

this onProgress(EventListener<NodeProgressEvent<T>> listener) fluent

Adds a listener that runs on every frame where the progress changes, with the progress and the current time.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page