iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML Audio/Video

Quick reference for the JavaScript API shared by <audio> and <video>.

Properties

PropertyMeaning
currentTimePlayback position in seconds. Assignable.
durationTotal length in seconds.
pausedWhether playback is paused.
endedWhether playback has finished.
volume0.0 to 1.0.
mutedBoolean.
playbackRate1.0 = normal, 2.0 = double speed.
loopBoolean.
autoplayBoolean.
buffered / seekableTimeRanges of buffered / seekable spans.
readyState0–4: how much data is loaded.
networkState0–3: download status.
videoWidth / videoHeightIntrinsic video size (video only).

Methods

MethodEffect
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>

Test yourself

Q1. Most universal modern video codec is…
Q2. Multiple sources let the browser…
Q3. Show subtitles with…

Discussion

Loading…