Home  >  Article  >  Web Front-end  >  Use html to implement an audio playback code

Use html to implement an audio playback code

零下一度
零下一度Original
2017-04-22 16:01:1412205browse

Player with controls

html<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>播放音频</title>
</head>
<body>
<audio src="raw/1.mp3" controls="controls">你的浏览器不支持</audio>
</body>
</html>

The player is not visible, use buttons to control playback

html<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>播放音频</title>
</head>
<body>
<button onclick="clickA()">播放/暂停</button>
<audio id="audio" src="raw/1.mp3">你的浏览器不支持</audio>
<script>
    var a=document.getElementById("audio");
    function clickA(){
        if(a.paused){
            a.play();
        }else{
            a.pause();
        }
    }
</script>
</body>
</html>

Player with controls

html<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>播放音频</title>
</head>
<body>
<audio src="raw/1.mp3" controls="controls">你的浏览器不支持</audio>
</body>
</html>

The player is not visible, use buttons Control playback

html<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>播放音频</title>
</head>
<body>
<button onclick="clickA()">播放/暂停</button>
<audio id="audio" src="raw/1.mp3">你的浏览器不支持</audio>
<script>
    var a=document.getElementById("audio");
    function clickA(){
        if(a.paused){
            a.play();
        }else{
            a.pause();
        }
    }
</script>
</body>
</html>


The above is the detailed content of Use html to implement an audio playback code. 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