Home  >  Article  >  Web Front-end  >  How to stop playing video in html5 video

How to stop playing video in html5 video

青灯夜游
青灯夜游Original
2021-05-20 16:30:2515457browse

html5 video method to stop playing a video: first use "document.getElementById("id value")" to obtain the video object; then use the "video object.pause()" statement to stop (pause) the currently playing video Just video.

How to stop playing video in html5 video

The operating environment of this tutorial: windows7 system, HTML5&&javascript version 1.8.5, Dell G3 computer.

html5 videoStop playing video

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
</head>
<body> 

<div style="text-align:center"> 
  <button onclick="playPause()">播放/暂停</button> 
  <br><br>
  <video id="video1" width="420">
    <source src="mov_bbb.mp4" type="video/mp4">
    <source src="mov_bbb.ogg" type="video/ogg">
    您的浏览器不支持 HTML5 video 标签。
  </video>
</div> 

<script> 
var myVideo=document.getElementById("video1"); 

function playPause()
{ 
	if (myVideo.paused) 
	  myVideo.play(); 
	else 
	  myVideo.pause(); 
} 
</script> 

</body> 
</html>

Rendering:

How to stop playing video in html5 video

Related function description:

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

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

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of How to stop playing video in html5 video. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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