这是一个开始播放所需音频的工作脚本。有人能通过再次点击onclick段落来告诉我们暂停或停止音频的好方法吗?
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=script, initial-scale=sript">
<title>English Homonyms</title>
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript">
function play(param) {
const playlist = [
"0 => nincs",
"audio/audio_01.mp3",
"audio/audio_02.mp3",
"audio/audio_03.mp3"
];
var list = param;
var music = playlist[param];
var audio = new Audio(music);
audio.play();
}
</script>
</head>
<body>
<h1>ENGLISH PRONUNCIATON NONSENSES – HOMONYMS</h1>
<p onclick = "play(1)">1. The bandage was wound around the wound.</p>
<p onclick = "play(2)">2. The farm was used to produce produce.</p>
<p onclick = "play(3)">3. The dump was so full that it had to refuse more refuse.</p>
</body>
</html>
let nowPlaying = 0
let nowAudio = new Audio()
function play(param) {
const playlist = [
"0 => nincs",
"audio/audio_01.mp3",
"audio/audio_02.mp3",
"audio/audio_03.mp3",
];
var lista = param;
var zene = playlist[param];
if (nowPlaying === param) {
if (nowAudio.paused) {
nowAudio.play()
} else {
nowAudio.pause()
}
} else {
nowAudio = new Audio(zene);
nowAudio.play();
nowPlaying = param
}
}