Home > Web Front-end > HTML Tutorial > How to implement play and pause in html

How to implement play and pause in html

醉折花枝作酒筹
Release: 2023-01-06 11:16:45
Original
7560 people have browsed it

In HTML, you can use the play method to play the current audio or video, and the pause method to pause the current audio or video. The syntax format is "element object.play()/pause()". These two methods are often used together, and video controls can be displayed using the controls property.

How to implement play and pause in html

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

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

All major browsers support the play() method.

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

pause() method stops (pauses) the currently playing audio or video.

Tip: This method is usually used with the play() method.

Tip: Use the controls attribute to display video controls (such as play, pause, search, volume, etc.).

<!DOCTYPEHTML>
<html>
<head>
<meta charset="utf-8">
<title>播放与暂停</title>
<script type="text/javascript">
var videoEl=null;
function Play(){
	videoEl.play();	  /* 播放视频 */
}
function Pause(){
	videoEl.pause();   /* 暂停播放 */
}
window.onload=function(){
	videoEl=document.getElementById("myPlayer");
}
</script>
</head>
<body>
<video id="myPlayer" src="resources/video.mp4" width="600" controls> 
  你的浏览器不支持video元素
</video><br>
<div id="time"></div>
<input type="button" value="播放" onclick="Play()" />
<input type="button" value="暂停" onclick="Pause()" />
</body>
</html>
Copy after login

Recommended learning: html video tutorial

The above is the detailed content of How to implement play and pause in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template