私たちは、4 つの異なる音を比較しているページを持つプロジェクトに取り組んでいます。私たちが使用しているスクリプトは各サウンドをうまく再生しますが、各リンクを押すと 4 つすべてが同時に再生されます。一度に 1 つの音だけが再生されるようにする方法を見つけようとしています。音「A」を押してから音「B」を押すと、音「A」が消えて「B」が鳴ります。
var html5_audiotypes={
"mp3": "audio/mpeg",
"ogg": "audio/ogg",
}
function createsoundbite(sound){
var html5audio=document.createElement('audio')
if (html5audio.canPlayType){
for (var i=0; i<arguments.length; i++){
var sourceel=document.createElement('source')
sourceel.setAttribute('src', arguments[i])
if (arguments[i].match(/\.(\w+)$/i))
sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
html5audio.appendChild(sourceel)
}
html5audio.load()
html5audio.playclip=function(){
html5audio.pause()
html5audio.currentTime=0
html5audio.play()
}
return html5audio
}