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

html5 method pause() to stop (pause) the currently playing audio or video

黄舟
Release: 2017-11-08 09:29:14
Original
11614 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

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

Browser support

All major browsers support the pause() method.

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

Syntax

audio|video.pause()
Copy after login

If we want to use js to control the pause and playback of audio, we cannot directly add click events on the audio, we need to add another button to bind it Click event.

HTML code is as follows:

<button onclick="playPause()">播放/暂停</button>
<audio id="audio1" width="420" >
    <source src="example.mp4" type="audio/mp4" />
    <source src="example.ogg" type="audio/ogg" />
</audio>
Copy after login

JS code is as follows:

var myAudio = document.getElementById(&#39;audio1&#39;);
    function playPause(){
        if(myAudio.paused){
            myAudio.play();
        }else{
            myAudio.pause();
        }
    }
Copy after login


The above is the detailed content of html5 method pause() to stop (pause) the currently playing audio or video. 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!