Record Class VideoPart

java.lang.Object
java.lang.Record
com.tnsai.models.chat.VideoPart
All Implemented Interfaces:
ContentPart

public record VideoPart(String data, String mimeType, VideoPart.VideoSource source) extends Record implements ContentPart
Represents a video part of a message. Supports Base64 data, file path, or URL.

Supported formats depend on the provider:

  • Gemini: mp4, mpeg, mov, avi, webm, mkv, 3gpp, flv

Note: Video understanding is currently supported by:

  • Google Gemini (all versions)

Usage examples:


 // From Base64 data
 VideoPart video = VideoPart.fromBase64(base64Data, "video/mp4");

 // From file
 VideoPart video = VideoPart.fromFile(new File("demo.mp4"));

 // From URL
 VideoPart video = VideoPart.fromUrl("https://example.com/video.mp4");
 
  • Constructor Details

    • VideoPart

      public VideoPart(String data, String mimeType, VideoPart.VideoSource source)
      Creates an instance of a VideoPart record class.
      Parameters:
      data - the value for the data record component
      mimeType - the value for the mimeType record component
      source - the value for the source record component
  • Method Details

    • fromBase64

      public static VideoPart fromBase64(String base64Data, String mimeType)
      Creates a VideoPart from Base64 encoded data.
      Parameters:
      base64Data - The Base64 encoded video data
      mimeType - The MIME type (e.g., "video/mp4", "video/webm")
      Returns:
      VideoPart with Base64 source
    • fromUrl

      public static VideoPart fromUrl(String url)
      Creates a VideoPart from a URL.
      Parameters:
      url - The URL pointing to the video file
      Returns:
      VideoPart with URL source
    • fromFile

      public static VideoPart fromFile(File file)
      Creates a VideoPart from a file. The file is read and encoded as Base64.

      Warning: Video files can be large. Consider using URL-based uploads for files larger than 20MB.

      Parameters:
      file - The video file
      Returns:
      VideoPart with Base64 encoded file contents
      Throws:
      RuntimeException - if file cannot be read
    • fromBytes

      public static VideoPart fromBytes(byte[] bytes, String mimeType)
      Creates a VideoPart from a byte array.
      Parameters:
      bytes - The video bytes
      mimeType - The MIME type
      Returns:
      VideoPart with Base64 encoded data
    • getType

      public String getType()
      Specified by:
      getType in interface ContentPart
    • isUrl

      public boolean isUrl()
      Returns true if this is a URL-based video part.
    • isBase64

      public boolean isBase64()
      Returns true if this is a Base64-based video part.
    • getBytes

      public byte[] getBytes()
      Gets the raw bytes if this is a Base64 video part.
      Returns:
      Decoded bytes
      Throws:
      IllegalStateException - if source is URL
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • data

      public String data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • mimeType

      public String mimeType()
      Returns the value of the mimeType record component.
      Returns:
      the value of the mimeType record component
    • source

      public VideoPart.VideoSource source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component