Video Methods
Video Methods
Here are four commonly used HTML audio/video methods along with explanations and
examples:
1. play()
The play() method is used to play the audio or video. If the media is paused or hasn't
started yet, calling this method starts playback.
html
<!DOCTYPE html>
<html lang="en">
<head>
<title>play() Example</title>
</head>
<body>
<audio id="myAudio" src="audio.mp3"></audio>
<button onclick="document.getElementById('myAudio').play()">Play Audio</button>
</body>
</html>
Explanation: When the button is clicked, the play() method is triggered to start playing the
audio.
2. pause()
The pause() method pauses the audio or video that is currently playing.
html
1/3
<!DOCTYPE html>
<html lang="en">
<head>
<title>pause() Example</title>
</head>
<body>
<audio id="myAudio" src="audio.mp3" controls></audio>
<button onclick="document.getElementById('myAudio').pause()">Pause
Audio</button>
</body>
</html>
Explanation: The pause() method stops the playback at the current position. You can
resume it later using the play() method.
3. load()
The load() method reloads the audio or video element. It can be useful if you want to reset
or refresh the media.
html
<!DOCTYPE html>
<html lang="en">
<head>
<title>load() Example</title>
</head>
<body>
<video id="myVideo" width="320" height="240" controls>
<source src="video.mp4" type="video/mp4">
</video>
<button onclick="document.getElementById('myVideo').load()">Reload
Video</button>
</body>
</html>
Explanation: Clicking the "Reload Video" button resets the video, reloading its source.
2/3
4. currentTime
The currentTime property allows you to set or get the current playback position of an audio
or video element.
html
<!DOCTYPE html>
<html lang="en">
<head>
<title>currentTime Example</title>
</head>
<body>
<video id="myVideo" width="320" height="240" controls>
<source src="video.mp4" type="video/mp4">
</video>
<button onclick="document.getElementById('myVideo').currentTime = 10">Skip to
10s</button>
</body>
</html>
Explanation: The currentTime property skips the playback to a specified time (e.g., 10
seconds in this example).
These methods are part of the HTMLMediaElement interface and work for both <audio>
and <video> elements, enabling easy control over multimedia playback.
3/3