Home > Article > Web Front-end > Use html to implement an audio playback code
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!