Home  >  Article  >  Web Front-end  >  How to start playing the current audio or video in html5

How to start playing the current audio or video in html5

黄舟
黄舟Original
2017-11-07 14:05:282752browse

Example

A video with play and pause buttons:

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

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()

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>

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!

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