声音脚本播放开/关

时间:2012-11-11 02:44:28

标签: javascript

我们正在开发一个项目,其中有一个页面,我们正在比较4种不同的声音。我们使用的脚本播放每个声音都很好,但是你可以按下每个链接,所有4个可以同时播放。我们正试图弄清楚如何制作它,以便一次只播放一种声音。如果按声音" 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
}

0 个答案:

没有答案
相关问题