Class Source
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasSize,HasStyle,Serializable
<source> element — one of the
alternative files a Video or an Audio can play.
A media component lists the same recording in several formats, each as a
source of its own, and the browser plays the first one it can decode. The
type tells it which that is without downloading
anything, so give it whenever you know the format.
Sources are usually created through Media.addSource(String, String)
rather than directly.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSource()Creates a new source without a URL.Source(DownloadHandler downloadHandler, @Nullable String type) Creates a new source for the media file that the given download handler serves.Creates a new source for the media file at the given URL. -
Method Summary
Modifier and TypeMethodDescription@Nullable StringgetSrc()Gets the URL of the media file.@Nullable StringgetType()Gets the MIME type of the media file.voidsetSrc(DownloadHandler downloadHandler) Sets the URL of the media file to the URL of the givenDownloadHandlercallback.voidSets the URL of the media file.voidSets the MIME type of the media file, such asvideo/mp4oraudio/mpeg.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
Source
public Source()Creates a new source without a URL. -
Source
Creates a new source for the media file at the given URL.- Parameters:
src- the URL of the media filetype- the MIME type of the media file, such asvideo/mp4, ornullwhen it is not known- See Also:
-
Source
Creates a new source for the media file that the given download handler serves.Sets the
Content-Dispositionheader toinlinefor pre-defined download handlers, created by factory methods inDownloadHandler, as well as for otherAbstractDownloadHandlerimplementations.- Parameters:
downloadHandler- the download handler that serves the media file, notnulltype- the MIME type of the media file, such asvideo/mp4, ornullwhen it is not known- See Also:
-
-
Method Details
-
setSrc
Sets the URL of the media file.- Parameters:
src- the URL of the media file, ornullto remove the URL
-
setSrc
Sets the URL of the media file to the URL of the givenDownloadHandlercallback.Sets the
Content-Dispositionheader toinlinefor pre-defined download handlers, created by factory methods inDownloadHandler, as well as for otherAbstractDownloadHandlerimplementations.The handler is wrapped with
DownloadHandler.allowDisabled()so that the media file is still served when the media component, or one of its ancestors, is disabled. The browser fetches it as part of rendering rather than as a user action, so blocking the request on the disabled state would leave the player empty.- Parameters:
downloadHandler- the download handler that serves the media file, notnull- See Also:
-
getSrc
Gets the URL of the media file.- Returns:
- the URL of the media file, or
nullif none has been set - See Also:
-
setType
Sets the MIME type of the media file, such asvideo/mp4oraudio/mpeg. A codec parameter may be included, as invideo/webm; codecs="vp9, opus".The browser skips a source whose type it cannot play without requesting the file, so a type that is set saves a download on every browser that plays one of the other sources.
- Parameters:
type- the MIME type of the media file, ornullto remove the type
-
getType
Gets the MIME type of the media file.- Returns:
- the MIME type, or
nullif none has been set - See Also:
-