# Basic HTML example
<video poster="preview_image.png" controls>
<source src="or_here.webm" type="video/webm" />
<source src="alternative_if_browser_cant_pay_first_source.mp4" type="video/mp4" />
<track src="optional_subtitles.vtt" kind="subtitles" srclang="de" label="Deutsch" default>
</video>
# Javascript API (notable methods and properties)
video = document.querySelector('video')
video.play()
video.pause()
video.load() // Reset to the beginning and select the best available source
video.currentSrc // The selected source
video.currentTime // The current playback time (in seconds)
video.ended // Whether the video has finished
video.muted
video.paused
video.readyState // See comments
video.volume
Comments
-
controlsmakes the browser show its own video controls - The image given in
posterwill be shown before the video was loaded/has started (and if the video cannot be loaded at all). - The browser will play the first
sourceit can play (some video types are not supported in every browser). The video can also be given assrcon thevideoelement; however, this excludes the handy fallback mechanism. - The
trackelement can be used to add either captions, subtitles, chapters, descriptions or similar metadata. - If the video has not started to play and has not been seeked,
currentTimeis the video's initial playback time. Setting this value seeks to the new time. -
readyStatereturns a value in [0:4] indicating its state Show archive.org snapshot .
Caveats
- On iOS, the
video.preloadattribute is ignored. iOS seems to always load the full video once it has asrc. - When creating a video element with
document.createElement('video'), setting themutedattribute will not mute the video! Usevideo.muted = trueinstead.
Resources
- Mozilla docs on the HTML video element Show archive.org snapshot (recommended) – implemented HTML APIs: HTMLVideoElement Show archive.org snapshot , HTMLMediaElement Show archive.org snapshot , HTMLElement Show archive.org snapshot
-
CanIUse
Show archive.org snapshot
: Supported by all browsers since 2013 (except Opera Mini). Desktop and mobile Safari ignore the
autoplayattribute. - Tutorial: Creating a cross-browser video player Show archive.org snapshot
- Video transcoding: Web and native playback overview (April 2020)
Full Documentation on the video element
Posted by Dominik Schöler to makandra dev (2020-07-09 09:58)