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">&lt;video&gt;</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 * <h2 class='section'>Examples:</h2>
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 *
091 * <h2 class='section'>See Also:</h2><ul>
092 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
093 * </ul>
094 */
095@Marshalled(typeName = "video")
096public class Video extends HtmlElementMixed<Video> {
097
098   /**
099    * Creates an empty {@link Video} element.
100    */
101   public Video() {}
102
103   /**
104    * Creates a {@link Video} element with the specified {@link Video#src(Object)} attribute.
105    *
106    * @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).
107    */
108   public Video(Object src) {
109      src(src);
110   }
111
112   /**
113    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay">autoplay</a>
114    * attribute.
115    *
116    * <p>
117    * Hint that the media resource can be started automatically when the page is loaded.
118    *
119    * <p>
120    * This attribute uses deminimized values:
121    * <ul>
122    *    <li><jk>false</jk> - Attribute is not added</li>
123    *    <li><jk>true</jk> - Attribute is added as <js>"autoplay"</js></li>
124    *    <li>Other values - Passed through as-is</li>
125    * </ul>
126    *
127    * @param value
128    *    The new value for this attribute.
129    *    Typically a {@link Boolean} or {@link String}.
130    *    Can be <jk>null</jk> to unset the attribute.
131    * @return This object.
132    */
133   public Video autoplay(Object value) {
134      attr("autoplay", deminimize(value, "autoplay"));
135      return this;
136   }
137
138   /**
139    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls">controls</a>
140    * attribute.
141    *
142    * <p>
143    * Show user agent controls.
144    *
145    * <p>
146    * This attribute uses deminimized values:
147    * <ul>
148    *    <li><jk>false</jk> - Attribute is not added</li>
149    *    <li><jk>true</jk> - Attribute is added as <js>"controls"</js></li>
150    *    <li>Other values - Passed through as-is</li>
151    * </ul>
152    *
153    * @param value
154    *    The new value for this attribute.
155    *    Typically a {@link Boolean} or {@link String}.
156    *    Can be <jk>null</jk> to unset the attribute.
157    * @return This object.
158    */
159   public Video controls(Object value) {
160      attr("controls", deminimize(value, "controls"));
161      return this;
162   }
163
164   /**
165    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-crossorigin">crossorigin</a>
166    * attribute.
167    *
168    * <p>
169    * Specifies how the element handles cross-origin requests for CORS (Cross-Origin Resource Sharing).
170    *
171    * <p>
172    * Possible values:
173    * <ul>
174    *    <li><js>"anonymous"</js> - Cross-origin requests are made without credentials</li>
175    *    <li><js>"use-credentials"</js> - Cross-origin requests include credentials</li>
176    * </ul>
177    *
178    * @param value How to handle cross-origin requests. Can be <jk>null</jk> to unset the attribute.
179    * @return This object.
180    */
181   public Video crossorigin(String value) {
182      attr("crossorigin", value);
183      return this;
184   }
185
186   /**
187    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-height">height</a>
188    * attribute.
189    *
190    * <p>
191    * Vertical dimension.
192    *
193    * @param value
194    *    The new value for this attribute.
195    *    Typically a {@link Number} or {@link String}.
196    *    Can be <jk>null</jk> to unset the attribute.
197    * @return This object.
198    */
199   public Video height(Object value) {
200      attr("height", value);
201      return this;
202   }
203
204   /**
205    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop">loop</a> attribute.
206    *
207    * <p>
208    * Causes the media to automatically restart from the beginning when it reaches the end.
209    *
210    * @param value If <jk>true</jk>, the media will loop continuously. Can be <jk>null</jk> to unset the attribute.
211    * @return This object.
212    */
213   public Video loop(Object value) {
214      attr("loop", value);
215      return this;
216   }
217
218   /**
219    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-mediagroup">mediagroup</a>
220    * attribute.
221    *
222    * <p>
223    * Groups multiple media elements together so they can be controlled as a single unit. All media elements
224    * with the same mediagroup value will share the same MediaController, allowing synchronized playback.
225    *
226    * <p>
227    * This is useful for creating synchronized audio/video presentations or multiple camera angles.
228    *
229    * @param value The name of the media group to join. Can be <jk>null</jk> to unset the attribute.
230    * @return This object.
231    */
232   public Video mediagroup(String value) {
233      attr("mediagroup", value);
234      return this;
235   }
236
237   /**
238    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-muted">muted</a>
239    * attribute.
240    *
241    * <p>
242    * Mutes the audio output by default. Useful for autoplay videos where audio should be disabled initially.
243    *
244    * @param value If <jk>true</jk>, the media will be muted by default. Can be <jk>null</jk> to unset the attribute.
245    * @return This object.
246    */
247   public Video muted(Object value) {
248      attr("muted", value);
249      return this;
250   }
251
252   /**
253    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster">poster</a>
254    * attribute.
255    *
256    * <p>
257    * Specifies an image to display as a placeholder before the video starts playing. This image is shown
258    * while the video is loading or before the user clicks play.
259    *
260    * <p>
261    * The poster image should be representative of the video content and help users understand what the video contains.
262    *
263    * @param value The URL of the poster image to display before video playback. Can be <jk>null</jk> to unset the attribute.
264    * @return This object.
265    */
266   public Video poster(String value) {
267      attr("poster", value);
268      return this;
269   }
270
271   /**
272    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload">preload</a>
273    * attribute.
274    *
275    * <p>
276    * Specifies how the browser should load the media resource.
277    *
278    * <p>
279    * Possible values:
280    * <ul>
281    *    <li><js>"none"</js> - Do not preload the media</li>
282    *    <li><js>"metadata"</js> - Preload only metadata (duration, dimensions, etc.)</li>
283    *    <li><js>"auto"</js> - Preload the entire media file (default)</li>
284    * </ul>
285    *
286    * @param value How much of the media to preload. Can be <jk>null</jk> to unset the attribute.
287    * @return This object.
288    */
289   public Video preload(String value) {
290      attr("preload", value);
291      return this;
292   }
293
294   /**
295    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-src">src</a> attribute.
296    *
297    * <p>
298    * Address of the resource.
299    *
300    * <p>
301    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
302    * Strings must be valid URIs.
303    *
304    * <p>
305    * URIs defined by {@link UriResolver} can be used for values.
306    *
307    * @param value
308    *    The new value for this attribute.
309    *    Typically a {@link URL} or {@link String}.
310    *    Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed).
311    * @return This object.
312    */
313   public Video src(Object value) {
314      attrUri("src", value);
315      return this;
316   }
317
318   /**
319    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-width">width</a> attribute.
320    *
321    * <p>
322    * Horizontal dimension.
323    *
324    * @param value
325    *    The new value for this attribute.
326    *    Typically a {@link Number} or {@link String}.
327    *    Can be <jk>null</jk> to unset the attribute.
328    * @return This object.
329    */
330   public Video width(Object value) {
331      attr("width", value);
332      return this;
333   }
334}