Loads and starts playback of a media resource.
Method of dom/HTMLMediaElementdom/HTMLMediaElement
Syntax object.play();
Return Value
No return value
ExamplesPlay method example.
<!DOCTYPE html>
<html>
<head>
<title>Simple Video Example</title>
<script>
function hidecontrol(e) {
var video = document.getElementById('video1');
if (video.controls == true) {
video.removeAttribute("controls");
e.innerHTML = "Show controls";
} else {
video.setAttribute("controls", true);
e.innerHTML = "Hide controls";
}
}
function playVideo(e) {
var video = document.getElementById('video1');
if (video.paused) {
var input = document.getElementById('videoFile');
if (input.value) {
if (input.value != video.src) {
video.src = input.value;
}
video.play();
e.innerHTML = "Pause";
}
} else {
video.pause();
e.innerHTML = "Play";
}
}
</script>
</head>
<body>
<video id="video1" controls >HTML5 video is not supported</video><br />
<input type="text" id="videoFile" size="60" placeholder="Enter video file URL here"/>
<button onclick="playVideo(this);">Play</button>
<button onclick="hidecontrol(this);">Hide controls</button>
</body>
</html>
Notes Remarks
To change the URL that is currently playing, assign it to src. This method sets paused to false. To change the URL using the source element, or if the original video was specified by the source element, call load before calling play.
Standards informationaudio
audio
video
Microsoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4