001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.html5; 018 019import java.net.*; 020 021import org.apache.juneau.marshall.*; 022 023/** 024 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#the-video-element"><video></a> 025 * element. 026 * 027 * <p> 028 * The video element is used to embed video content in an HTML document. It provides a way to include 029 * video files that can be played by the browser's built-in video player. The video element supports 030 * multiple video formats and provides various attributes for controlling playback, appearance, and 031 * behavior. It can contain source elements to specify multiple video formats for browser compatibility. 032 * 033 * <h5 class='section'>Examples:</h5> 034 * <p class='bcode w800'> 035 * <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*; 036 * 037 * <jc>// Simple video with controls</jc> 038 * Video <jv>simple</jv> = <jsm>video</jsm>() 039 * .src(<js>"movie.mp4"</js>) 040 * .controls(<jk>true</jk>) 041 * .width(640) 042 * .height(360); 043 * 044 * <jc>// Video with multiple sources</jc> 045 * Video <jv>multiple</jv> = <jsm>video</jsm>( 046 * <jsm>source</jsm>().src(<js>"movie.mp4"</js>).type(<js>"video/mp4"</js>), 047 * <jsm>source</jsm>().src(<js>"movie.webm"</js>).type(<js>"video/webm"</js>), 048 * <jsm>source</jsm>().src(<js>"movie.ogg"</js>).type(<js>"video/ogg"</js>) 049 * ).controls(<jk>true</jk>); 050 * 051 * <jc>// Autoplay video (muted for browser compatibility)</jc> 052 * Video <jv>autoplay</jv> = <jsm>video</jsm>() 053 * .src(<js>"intro.mp4"</js>) 054 * .autoplay(<jk>true</jk>) 055 * .muted(<jk>true</jk>) 056 * .loop(<jk>true</jk>); 057 * 058 * <jc>// Video with poster image</jc> 059 * Video <jv>poster</jv> = <jsm>video</jsm>() 060 * .src(<js>"trailer.mp4"</js>) 061 * .poster(<js>"trailer-poster.jpg"</js>) 062 * .controls(<jk>true</jk>) 063 * .width(800) 064 * .height(450); 065 * 066 * <jc>// Video with custom styling</jc> 067 * Video <jv>styled</jv> = <jsm>video</jsm>() 068 * .src("presentation.mp4") 069 * .controls(true) 070 * .class_("video-player") 071 * .style("border: 2px solid #ccc; border-radius: 8px;"); 072 * 073 * // Video with event handlers 074 * Video interactive = new Video() 075 * .src("tutorial.mp4") 076 * .controls(true) 077 * .onplay("trackVideoPlay()") 078 * .onended("showNextVideo()"); 079 * </p> 080 * 081 * <p> 082 * The following convenience methods are provided for constructing instances of this bean: 083 * <ul class='javatree'> 084 * <li class='jc'>{@link HtmlBuilder} 085 * <ul class='javatree'> 086 * <li class='jm'>{@link HtmlBuilder#video() video()} 087 * <li class='jm'>{@link HtmlBuilder#video(Object) video(Object)} 088 * </ul> 089 * </ul> 090 * </p> 091 * 092 * <h5 class='section'>See Also:</h5><ul> 093 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 094 * </ul> 095 */ 096@Marshalled(typeName = "video") 097public class Video extends HtmlElementMixed<Video> { 098 099 /** 100 * Creates an empty {@link Video} element. 101 */ 102 public Video() {} 103 104 /** 105 * Creates a {@link Video} element with the specified {@link Video#src(Object)} attribute. 106 * 107 * @param src The {@link Video#src(Object)} attribute. Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed). 108 */ 109 public Video(Object src) { 110 src(src); 111 } 112 113 /** 114 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay">autoplay</a> 115 * attribute. 116 * 117 * <p> 118 * Hint that the media resource can be started automatically when the page is loaded. 119 * 120 * <p> 121 * This attribute uses deminimized values: 122 * <ul> 123 * <li><jk>false</jk> - Attribute is not added</li> 124 * <li><jk>true</jk> - Attribute is added as <js>"autoplay"</js></li> 125 * <li>Other values - Passed through as-is</li> 126 * </ul> 127 * 128 * @param value 129 * The new value for this attribute. 130 * Typically a {@link Boolean} or {@link String}. 131 * Can be <jk>null</jk> to unset the attribute. 132 * @return This object. 133 */ 134 public Video autoplay(Object value) { 135 attr("autoplay", deminimize(value, "autoplay")); 136 return this; 137 } 138 139 /** 140 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls">controls</a> 141 * attribute. 142 * 143 * <p> 144 * Show user agent controls. 145 * 146 * <p> 147 * This attribute uses deminimized values: 148 * <ul> 149 * <li><jk>false</jk> - Attribute is not added</li> 150 * <li><jk>true</jk> - Attribute is added as <js>"controls"</js></li> 151 * <li>Other values - Passed through as-is</li> 152 * </ul> 153 * 154 * @param value 155 * The new value for this attribute. 156 * Typically a {@link Boolean} or {@link String}. 157 * Can be <jk>null</jk> to unset the attribute. 158 * @return This object. 159 */ 160 public Video controls(Object value) { 161 attr("controls", deminimize(value, "controls")); 162 return this; 163 } 164 165 /** 166 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-crossorigin">crossorigin</a> 167 * attribute. 168 * 169 * <p> 170 * Specifies how the element handles cross-origin requests for CORS (Cross-Origin Resource Sharing). 171 * 172 * <p> 173 * Possible values: 174 * <ul> 175 * <li><js>"anonymous"</js> - Cross-origin requests are made without credentials</li> 176 * <li><js>"use-credentials"</js> - Cross-origin requests include credentials</li> 177 * </ul> 178 * 179 * @param value How to handle cross-origin requests. Can be <jk>null</jk> to unset the attribute. 180 * @return This object. 181 */ 182 public Video crossorigin(String value) { 183 attr("crossorigin", value); 184 return this; 185 } 186 187 /** 188 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-height">height</a> 189 * attribute. 190 * 191 * <p> 192 * Vertical dimension. 193 * 194 * @param value 195 * The new value for this attribute. 196 * Typically a {@link Number} or {@link String}. 197 * Can be <jk>null</jk> to unset the attribute. 198 * @return This object. 199 */ 200 public Video height(Object value) { 201 attr("height", value); 202 return this; 203 } 204 205 /** 206 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop">loop</a> attribute. 207 * 208 * <p> 209 * Causes the media to automatically restart from the beginning when it reaches the end. 210 * 211 * @param value If <jk>true</jk>, the media will loop continuously. Can be <jk>null</jk> to unset the attribute. 212 * @return This object. 213 */ 214 public Video loop(Object value) { 215 attr("loop", value); 216 return this; 217 } 218 219 /** 220 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-mediagroup">mediagroup</a> 221 * attribute. 222 * 223 * <p> 224 * Groups multiple media elements together so they can be controlled as a single unit. All media elements 225 * with the same mediagroup value will share the same MediaController, allowing synchronized playback. 226 * 227 * <p> 228 * This is useful for creating synchronized audio/video presentations or multiple camera angles. 229 * 230 * @param value The name of the media group to join. Can be <jk>null</jk> to unset the attribute. 231 * @return This object. 232 */ 233 public Video mediagroup(String value) { 234 attr("mediagroup", value); 235 return this; 236 } 237 238 /** 239 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-muted">muted</a> 240 * attribute. 241 * 242 * <p> 243 * Mutes the audio output by default. Useful for autoplay videos where audio should be disabled initially. 244 * 245 * @param value If <jk>true</jk>, the media will be muted by default. Can be <jk>null</jk> to unset the attribute. 246 * @return This object. 247 */ 248 public Video muted(Object value) { 249 attr("muted", value); 250 return this; 251 } 252 253 /** 254 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster">poster</a> 255 * attribute. 256 * 257 * <p> 258 * Specifies an image to display as a placeholder before the video starts playing. This image is shown 259 * while the video is loading or before the user clicks play. 260 * 261 * <p> 262 * The poster image should be representative of the video content and help users understand what the video contains. 263 * 264 * @param value The URL of the poster image to display before video playback. Can be <jk>null</jk> to unset the attribute. 265 * @return This object. 266 */ 267 public Video poster(String value) { 268 attr("poster", value); 269 return this; 270 } 271 272 /** 273 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload">preload</a> 274 * attribute. 275 * 276 * <p> 277 * Specifies how the browser should load the media resource. 278 * 279 * <p> 280 * Possible values: 281 * <ul> 282 * <li><js>"none"</js> - Do not preload the media</li> 283 * <li><js>"metadata"</js> - Preload only metadata (duration, dimensions, etc.)</li> 284 * <li><js>"auto"</js> - Preload the entire media file (default)</li> 285 * </ul> 286 * 287 * @param value How much of the media to preload. Can be <jk>null</jk> to unset the attribute. 288 * @return This object. 289 */ 290 public Video preload(String value) { 291 attr("preload", value); 292 return this; 293 } 294 295 /** 296 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-src">src</a> attribute. 297 * 298 * <p> 299 * Address of the resource. 300 * 301 * <p> 302 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 303 * Strings must be valid URIs. 304 * 305 * <p> 306 * URIs defined by {@link UriResolver} can be used for values. 307 * 308 * @param value 309 * The new value for this attribute. 310 * Typically a {@link URL} or {@link String}. 311 * Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed). 312 * @return This object. 313 */ 314 public Video src(Object value) { 315 attrUri("src", value); 316 return this; 317 } 318 319 /** 320 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-width">width</a> attribute. 321 * 322 * <p> 323 * Horizontal dimension. 324 * 325 * @param value 326 * The new value for this attribute. 327 * Typically a {@link Number} or {@link String}. 328 * Can be <jk>null</jk> to unset the attribute. 329 * @return This object. 330 */ 331 public Video width(Object value) { 332 attr("width", value); 333 return this; 334 } 335}