Last active
August 11, 2023 07:04
-
-
Save yoshiiz/6134482f8fd72063e7221b7b82d27e67 to your computer and use it in GitHub Desktop.
[JavaScript] 複数の音楽ファイルを連続で再生しループする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>連続再生ループ</title> | |
</head> | |
<body> | |
<audio id='audio'></audio> | |
<script type="text/javascript"> | |
'use strict'; | |
var playlist = [ | |
'./sample1.wav', | |
'./sample2.wav', | |
'./sample3.wav', | |
'./sample4.wav', | |
'./sample5.wav' | |
] | |
var audio = document.createElement('audio'); | |
document.body.appendChild(audio); | |
audio.style.width = '100%'; | |
audio.style.height = 'auto'; | |
audio.controls = true; | |
audio.volume = 0.2; | |
audio.src = playlist[0]; | |
audio.play(); | |
var index = 0; | |
audio.addEventListener('ended', function(){ | |
index++; | |
if (index < playlist.length) { | |
audio.src = playlist[index]; | |
audio.play(); | |
} | |
else { | |
audio.src = playlist[0]; | |
audio.play(); | |
index = 0; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment