Package com.tnsai.models.chat
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");
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionVideoPart(String data, String mimeType, VideoPart.VideoSource source) Creates an instance of aVideoPartrecord class. -
Method Summary
Modifier and TypeMethodDescriptiondata()Returns the value of thedatarecord component.final booleanIndicates whether some other object is "equal to" this one.static VideoPartfromBase64(String base64Data, String mimeType) Creates a VideoPart from Base64 encoded data.static VideoPartCreates a VideoPart from a byte array.static VideoPartCreates a VideoPart from a file.static VideoPartCreates a VideoPart from a URL.byte[]getBytes()Gets the raw bytes if this is a Base64 video part.getType()final inthashCode()Returns a hash code value for this object.booleanisBase64()Returns true if this is a Base64-based video part.booleanisUrl()Returns true if this is a URL-based video part.mimeType()Returns the value of themimeTyperecord component.source()Returns the value of thesourcerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
VideoPart
Creates an instance of aVideoPartrecord class.- Parameters:
data- the value for thedatarecord componentmimeType- the value for themimeTyperecord componentsource- the value for thesourcerecord component
-
-
Method Details
-
fromBase64
Creates a VideoPart from Base64 encoded data.- Parameters:
base64Data- The Base64 encoded video datamimeType- The MIME type (e.g., "video/mp4", "video/webm")- Returns:
- VideoPart with Base64 source
-
fromUrl
Creates a VideoPart from a URL.- Parameters:
url- The URL pointing to the video file- Returns:
- VideoPart with URL source
-
fromFile
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
Creates a VideoPart from a byte array.- Parameters:
bytes- The video bytesmimeType- The MIME type- Returns:
- VideoPart with Base64 encoded data
-
getType
- Specified by:
getTypein interfaceContentPart
-
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
data
Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-
mimeType
Returns the value of themimeTyperecord component.- Returns:
- the value of the
mimeTyperecord component
-
source
Returns the value of thesourcerecord component.- Returns:
- the value of the
sourcerecord component
-