HTML音频播放器问题解决:点击图片无法播放音频
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>WebCat</title>
<style>
.player {
width: 300px;
margin: 10px auto;
}
<p>.progress-bar {
width: 100%;
height: 10px;
background-color: #ccc;
}</p>
<p>#progress {
width: 0;
height: 100%;
background-color: #ff0000;
}
.playdio{
width:30px;
height:30px;
}
</style></p>
</head>
<body>
<h1>Hello world</h1>
<div class="player">
<audio id="audio-player" src="55168229191131-232174176229191181.mp3" ></audio>
<img class="playdio" id="ui" src="img/gdt_ic_express_play.png" />
<div class="progress-bar">
<div id="progress"></div>
</div>
</div>
<script>
var img = document.getElementById("ui")
const audioPlayer = document.getElementById('audio-player');
const progressBar = document.getElementById('progress');
<p>audioPlayer.addEventListener('timeupdate', function() {
const progress = (audioPlayer.currentTime / audioPlayer.duration) * 100;
progressBar.style.width = <code>${progress}%</code>;
});
img.onclick=function (){
audioPlayer.play();
}
</script></p>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/pXV5 著作权归作者所有。请勿转载和采集!