+
95
-

回答

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BFW NEW PAGE</title>

</head>
<body>
<span id="bf"BfwOnclick="play();">播放/暂停</span>
<span id="bf"BfwOnclick="resume();">重新播放</span>
<audio src="//repo.bfw.wiki/bfwrepo/sound/5c89fd22dea6948307.mp3"></audio>
<script>
var videoEl = document.querySelector('audio');
function play() {
if (videoEl !== null) {
//检测播放是否已暂停.audio.paused 在播放器播放时返回false.

if (videoEl.paused) {
videoEl.play(); //audio.play();// 这个就是播放
} else {
videoEl.pause(); // 这个就是暂停
}
}

}
function resume() {
if (videoEl !== null) {
videoEl.currentTime = 0;
videoEl.play();

}
}

videoEl.addEventListener('play', function () {})
//播放进度监听
videoEl.addEventListener('timeupdate', function () {
var vTime = videoEl.currentTime;
var total_vtime = videoEl.duration;
//4秒后暂停播放
if (vTime >= 4) {
videoEl.currentTime = 0;
videoEl.pause();

}
})
</script>

</body>
</html>

网友回复

我知道答案,我要回答