2011-10-30 8 views
0

複数のサウンドを再生するには、次のスクリプトを入手するにはどうすればよいですか?私は1つだけを再生することができます。複数のソース

<script> 

// Mouseover/ Click sound effect- by JavaScript Kit (www.javascriptkit.com) 
// Visit JavaScript Kit at http://www.javascriptkit.com/ for full source code 

var html5_audiotypes={ //define list of audio file extensions 
"mp3": "audio/mpeg", 
"ogg": "audio/ogg", 
} 

function createsoundbite(sound){ 
var html5audio=document.createElement('audio') 
if (html5audio.canPlayType){ //check support for HTML5 audio 
    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 
} 
else{ 
    return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}} 
    } 
} 

//Initialize sound clips with 1 fallback file each: 

var mouseoversound=createsoundbite("/messages4u/2011/images/october/laugh.ogg", "/messages4u/2011/images/october/laugh.mp3") 

</script> 

HTML:

<area onmouseover="mouseoversound.playclip()" /> 

答えて

2

さて、あなただけあなたはそれが複数のサウンドを再生するには期待しない方法を1つの<audio>要素を持っていますか?

あなたは2つのサウンドエフェクトが必要な場合、あなたは2つの<audio>の要素を(あなたがただ一つの要素のソースを変更することができますが、それは厄介だと、おそらくあなたはそれがしたいどのように動作しません)が必要です。

関連する問題