Skip to content

Commit

Permalink
HTMLMediaElementのplayイベントの挙動を確認するためのサンプルを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
AXT-AyaKoto committed Jul 29, 2024
1 parent 98016e0 commit 8c7dcea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions htmlmediaelement-play-event/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="ja">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
</head>

<body>
<p>VOICEVOX:ナースロボ_タイプT</p>
<audio src="./test.wav"></audio>
<button onclick="play()">再生</button>
<pre></pre>
<script>
const play = () => {
const audio = document.querySelector('audio');
audio.addEventListener('play', () => {
setTimeout(() => {
document.querySelector("pre").innerText += `playイベント発火から1秒経過 :\n currentTime : ${audio.currentTime.toFixed(4)}\n`;
}, 1000);
});
audio.addEventListener('playing', () => {
setTimeout(() => {
document.querySelector("pre").innerText += `playingイベント発火から1秒経過 :\n currentTime : ${audio.currentTime.toFixed(4)}\n`;
}, 1000);
});
audio.addEventListener('timeupdate', () => {
const time = audio.currentTime;
setTimeout(() => {
document.querySelector("pre").innerText += `timeupdateイベント発火から1秒経過 :\n currentTime : ${audio.currentTime.toFixed(4)}\n fired at : ${time.toFixed(4)}\n diff : ${(audio.currentTime - time).toFixed(4)}\n`;
}, 1000);
}, {
once: true
});
audio.play();
}
</script>
</body>

</html>
Binary file added htmlmediaelement-play-event/test.wav
Binary file not shown.

0 comments on commit 8c7dcea

Please sign in to comment.