HTML Audio/Video
Quick reference for the JavaScript API shared by <audio> and <video>.
Properties
| Property | Meaning |
|---|---|
currentTime | Playback position in seconds. Assignable. |
duration | Total length in seconds. |
paused | Whether playback is paused. |
ended | Whether playback has finished. |
volume | 0.0 to 1.0. |
muted | Boolean. |
playbackRate | 1.0 = normal, 2.0 = double speed. |
loop | Boolean. |
autoplay | Boolean. |
buffered / seekable | TimeRanges of buffered / seekable spans. |
readyState | 0–4: how much data is loaded. |
networkState | 0–3: download status. |
videoWidth / videoHeight | Intrinsic video size (video only). |
Methods
| Method | Effect |
|---|---|
play() | Returns a Promise — handle rejection (autoplay policy). |
pause() | Pause immediately. |
load() | Reload the current src. |
canPlayType(type) | Returns "", "maybe", or "probably". |
Events
loadedmetadata, loadeddata, canplay, canplaythrough, play, playing, pause, ended, seeking, seeked, timeupdate, volumechange, ratechange, error, stalled, waiting.
Example
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Audio/Video</title>
</head>
<body>
<h1>HTML Audio/Video</h1>
<p>This is a demo page for the "HTML Audio/Video" lesson.</p>
</body>
</html>
Try it Yourself »
Exercise
Which attribute makes a <video> start playing automatically?
<video src="clip.mp4"
></video>
Eight letters; boolean.
Discussion
Loading…