Skip to content

Instantly share code, notes, and snippets.

@gouf
Last active June 8, 2024 15:52
Show Gist options
  • Save gouf/f383de0e7957f60107666b1295847406 to your computer and use it in GitHub Desktop.
Save gouf/f383de0e7957f60107666b1295847406 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!-- NOTE: JavaScript 側で、自動再生を有効化するには、一度 Play ボタンをクリックする必要がある -->
<div>
<input type="button" id="play" value="Play"/>
</div>
<div>
<audio controls src="https://upload.wikimedia.org/wikipedia/commons/0/0c/Meow_domestic_cat.ogg" id="audio"/>
</div>
</body>
</html>
// 2つの方法で; 2つの音声を同時再生 (動物の鳴き声)
document.addEventListener('DOMContentLoaded', (_e) => {
let playButton = document.querySelector('#play')
playButton.addEventListener('click', (_e) => {
let audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3')
audio.play()
//*/
let audio2 = document.querySelector('#audio')
audio2.play()
//*/
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment