Class UIVideo
java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UIVideo
Represents a UI element which plays a video (this can be considered a video player). The video is provided as
Playback is controlled from the plugin (
If the video has an audio track, it is played as 2D sound (first audio track only). Use
VideoAsset (if loaded from an URL, the client will stream it). The element size determines the video size.
Use Style.backgroundImageScaleMode to control how the video is fitted
into the element (stretch, scale to fit or scale and crop).Playback is controlled from the plugin (
play(), pause(), stop(), seek(float)),
every client decodes the video on its own. The client reports playback state changes through the
PlayerUIVideoEvent (e.g when the video is prepared, ended or failed to load).If the video has an audio track, it is played as 2D sound (first audio track only). Use
setVolume(float)
and setMuted(boolean) to control it.- See Also:
- Example: Play a video from an URL
-
Field Summary
Fields inherited from class UIElement
hoverStyle, style -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetVideo()Gets the current video asset.floatbooleanbooleanisMuted()booleanGets whether the video is currently playing (according to the last playback command).voidonVideoEvent(PlayerUIVideoEvent event) Override this method if you want to get video events (prepared, started, ended, error etc) directly, without having to register an event listener.voidpause()Pauses playback.voidplay()Starts or resumes playback (at the current position).voidplay(float startTime) Starts playback at a specific position.voidseek(float seconds) Jumps to a specific timeline position.voidsetLooping(boolean looping) Sets whether the video should loop.voidsetMuted(boolean muted) Mutes or unmutes the audio playback of the video.voidsetVideo(VideoAsset video) Sets the video asset.voidsetVolume(float volume) Sets the volume of the audio track of the video.voidstop()Stops playback and resets the position to the beginning.Methods inherited from class UIElement
addChild, addStyleSheet, addToClassList, getChildCount, getChilds, getID, getParent, getPluginID, isClickable, isDroppable, isPickable, onClick, onDropItem, removeAllChilds, removeChild, removeFromClassList, removeFromParent, removeStyleSheet, resetPivot, resetPosition, setBackgroundColor, setBackgroundColor, setBorder, setBorderColor, setBorderColor, setBorderEdgeRadius, setClickable, setDroppable, setOpacity, setPickable, setPivot, setPosition, setSize, setTextTooltip, setTextTooltip, setVisible, updateStyle
-
Constructor Details
-
UIVideo
public UIVideo() -
UIVideo
Creates a new video element.- Parameters:
video- the video asset to play.
-
-
Method Details
-
setVideo
Sets the video asset. If the element is already visible, the current video is stopped and replaced by the new one (playback does not start automatically, to do that, call explicitlyplay()).- Parameters:
video- the video asset, or null to remove the video.
-
getVideo
Gets the current video asset.- Returns:
- the video asset, or null if no video is set.
-
play
public void play()Starts or resumes playback (at the current position). -
play
public void play(float startTime) Starts playback at a specific position. This is useful if a player joins later and should see the video at the same position as the other players.- Parameters:
startTime- the position (in seconds) where playback should start.
-
pause
public void pause()Pauses playback. Callplay()to resume. -
stop
public void stop()Stops playback and resets the position to the beginning. If you just want to pause the video, callpause()instead. -
seek
public void seek(float seconds) Jumps to a specific timeline position.- Parameters:
seconds- the position (in seconds).
-
setLooping
public void setLooping(boolean looping) Sets whether the video should loop.- Parameters:
looping- true to loop the video, false to stop at the end (default behaviour).
-
isLooping
public boolean isLooping() -
isPlaying
public boolean isPlaying()Gets whether the video is currently playing (according to the last playback command).- Returns:
- true if playing, false if paused or stopped.
-
setVolume
public void setVolume(float volume) Sets the volume of the audio track of the video.- Parameters:
volume- the volume (0.0 - 1.0). Default: 1.0
-
getVolume
public float getVolume() -
setMuted
public void setMuted(boolean muted) Mutes or unmutes the audio playback of the video. By default, videos are not muted.- Parameters:
muted- true to mute the video, false to play its audio track.
-
isMuted
public boolean isMuted() -
onVideoEvent
Override this method if you want to get video events (prepared, started, ended, error etc) directly, without having to register an event listener.- Parameters:
event- the video event.
-