Class Source


@Marshalled(typeName="source") public class Source extends HtmlElementVoid<Source>
DTO for an HTML <source> element.

The source element specifies multiple media resources for media elements like audio and video. It allows browsers to choose the most appropriate source based on format support, bandwidth, and other factors. The source element is used inside audio and video elements to provide fallback options for different media formats.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Video with multiple sources Video video = video() .controls(true) .children( source().src("movie.mp4").type("video/mp4"), source().src("movie.webm").type("video/webm"), source().src("movie.ogg").type("video/ogg") ); // Audio with multiple sources Audio audio = audio() .controls(true) .children( source().src("sound.mp3").type("audio/mpeg"), source().src("sound.ogg").type("audio/ogg"), source().src("sound.wav").type("audio/wav") ); // Picture with multiple sources Picture picture = picture( source().src("image.webp").type("image/webp"), source().src("image.jpg").type("image/jpeg") ); // Source with media query Source responsive = source() .src("large-image.jpg") .media("(min-width: 800px)") .type("image/jpeg");

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

  • Method Details

    • src

      public Source src(Object value)
      src attribute.

      Address of the resource.

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      URIs defined by UriResolver can be used for values.

      Parameters:
      value - The new value for this attribute. Typically a URL or String. Can be null, in which case the attribute is stored with a null value (not removed).
      Returns:
      This object.
    • type

      public Source type(String value)
      type attribute.

      Specifies the MIME type of the media resource. Helps browsers determine if they can play the media and which source to use when multiple sources are provided.

      Common values:

      • "video/mp4" - MP4 video
      • "video/webm" - WebM video
      • "audio/mp3" - MP3 audio
      • "audio/ogg" - OGG audio
      • "audio/wav" - WAV audio
      Parameters:
      value - The MIME type of the media resource. Can be null to unset the attribute.
      Returns:
      This object.