Home > Web Front-end > H5 Tutorial > body text

How to start playing the current audio or video in html5

黄舟
Release: 2017-11-07 14:05:28
Original
2758 people have browsed it

Example

A video with play and pause buttons:

var myVideo=document.getElementById("video1");
function playVid()
  {  myVideo.play();
  }
function pauseVid()
  {
  myVideo.pause();
  }
Copy after login

Definition and usage

play() method starts playing the current audioor video.

Browser support

All major browsers support the play() method.

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

Grammar

audio|video.play()
Copy after login

Code example:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>视频播放</title>
</head>
<body>
<script>
      window.onload =function(){
          var ov=document.getElementById("a1");
          ov.onmouseover=function() {
               this.play();
          }
          ov.onmouseout =function() {
                this.pause();
          }

      };

</script>

<video  id="a1"  src="陈奕迅 - 陪你度过漫长岁月.mp4"  controls   loop width="400"  height="400">你的浏览器不支持</video>
</body>
</html>
Copy after login

The above is the detailed content of How to start playing the current audio or video in html5. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!