English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML Audio/Video DOM play() Method

The play() method allows media files to attempt to play(video/audio) and returns a Promise

 HTML Audio/Video DOM Reference Manual

Online Example

Video with Play and Pause Buttons:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Video play() Method Usage-Basic Tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="playVid()" type="button">Play Video</button>
<button onclick="pauseVid()" type="button">Pause Video</button> 
<br> 
<video id="video"1">
  <source src="movie.mp"4"type="video"/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script> 
var myVideo=document.getElementById("video",1"); 
function playVid()
{ 
  myVideo.play(); 
} 
function pauseVid()
{ 
  myVideo.pause(); 
} 
</script> 
</body>
</html>
Test to see ‹/›

Definition and Usage

The play() method starts playing the current audio or video.

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the play() method.

Note:Internet Explorer 8 and earlier versions do not support this method.

Syntax

audio|video.play()

 HTML Audio/Video DOM Reference Manual