Class Video

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasAriaLabel, HasComponents, HasComponentsOfType<Component>, HasElement, HasEnabled, HasSize, HasStyle, Serializable

@NullMarked @Tag("video") public class Video extends Media
Component representing a <video> element — the browser's built-in video player.

List the recording in as many formats as you want to support, one Source each, and the browser plays the first one it can decode:

 Video video = new Video();
 video.addSource("/intro.webm", "video/webm");
 video.addSource("/intro.mp4", "video/mp4");
 video.setControlsVisible(true);
 video.setPoster("/intro-poster.jpg");
 
The element has no controls of its own until Media.setControlsVisible(boolean) is called, so a player that the visitor is meant to start needs that call. Give the player a size through HasSize.setWidth(String) and HasSize.setHeight(String); without one, the page reflows once the video dimensions are known, unless a poster fixes the size earlier.
See Also:
  • Constructor Details

    • Video

      public Video()
      Creates a video player without any source.
    • Video

      public Video(Source... sources)
      Creates a video player that plays the first of the given sources the browser can decode.
      Parameters:
      sources - the same recording in one or more file formats
  • Method Details

    • setPoster

      public void setPoster(@Nullable String poster)
      Sets the URL of the image to show while the video is downloading, and before it is played for the first time. Without a poster, the browser shows the first frame of the video, which means it has to download part of the file before there is anything to look at.
      Parameters:
      poster - the URL of the poster image, or null to remove the poster
    • setPoster

      public void setPoster(DownloadHandler downloadHandler)
      Sets the poster image to the one that the given DownloadHandler callback serves. This is the version to use for an image the application produces itself, rather than one that is served from a URL of its own.

      Sets the Content-Disposition header to inline for pre-defined download handlers, created by factory methods in DownloadHandler, as well as for other AbstractDownloadHandler implementations.

      The handler is wrapped with DownloadHandler.allowDisabled() so that the poster is still served when the video, or one of its ancestors, is disabled. The browser fetches it as part of rendering rather than as a user action, so blocking the request on the disabled state would leave the player blank.

      Parameters:
      downloadHandler - the download handler that serves the poster image, not null
      See Also:
    • getPoster

      public @Nullable String getPoster()
      Gets the URL of the poster image.
      Returns:
      the URL of the poster image, or null if none has been set
      See Also: