Class UIVideo

java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UIVideo

public class UIVideo extends UIElement
Represents a UI element which plays a video (this can be considered a video player). The video is provided as 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
1//Load new video asset
2VideoAsset asset = VideoAsset.loadFromURL("https://www.w3schools.com/html/mov_bbb.mp4");
3
4//Create video player element
5UIVideo video = new UIVideo(asset);
6video.setSize(1280, 720, false);
7video.setPosition(50, 50, true);
8video.setPivot(Pivot.MiddleCenter);
9player.addUIElement(video);
10
11//Play the video
12video.play();
  • Constructor Details

    • UIVideo

      public UIVideo()
    • UIVideo

      public UIVideo(VideoAsset video)
      Creates a new video element.
      Parameters:
      video - the video asset to play.
  • Method Details

    • setVideo

      public void setVideo(VideoAsset video)
      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 explicitly play()).
      Parameters:
      video - the video asset, or null to remove the video.
    • getVideo

      public VideoAsset 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. Call play() to resume.
    • stop

      public void stop()
      Stops playback and resets the position to the beginning. If you just want to pause the video, call pause() 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

      public void onVideoEvent(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.
      Parameters:
      event - the video event.