我有以下代码:
var audiotypes={
"mp3": "audio/mpeg",
"mp4": "audio/mp4",
"ogg": "audio/ogg",
"wav": "audio/wav"
}
function ss_soundbits(sound){
var audio_element = document.createElement('audio')
if (audio_element.canPlayType){
for (var i=0; i<arguments.length; i++){
var source_element = document.createElement('source')
source_element.setAttribute('src', arguments[i])
if (arguments[i].match(/\.(\w+)$/i))
source_element.setAttribute('type', audiotypes[RegExp.$1])
audio_element.appendChild(source_element)
}
audio_element.load()
audio_element.playclip=function(){
audio_element.pause()
audio_element.currentTime=0
audio_element.play()
}
return audio_element
}
}
var clicksound = ss_soundbits('Door.ogg', "Door.mp3");
var plopsound = ss_soundbits('Pet.ogg', "Pet.mp3");
和
$("#button1").sequence("click")
.handle(function () {
$(".overlay").fadeToggle();
clicksound.playclip();
$(".overlay .repeat").click(function() { clicksound.playclip(); });
})
.handleNext("#button2", function () {
$(".overlay").fadeToggle();
plopsound.playclip();
$(".overlay .repeat").click(function() { plopsound.playclip(); });
})
一切运作良好,除非我点击#button2上的重复按钮,它还会播放来自button1(clickound)的声音 - 任何想法为什么会这样?我认为这可能是因为它是相同的元素 - 但我也尝试在#button2上的重复按钮上添加一个类并使用它来触发音频,但同样的事情发生 - 开放的想法!
答案 0 :(得分:0)
首先必须暂停上一个音频剪辑才能播放下一个 - 不知道为什么会有效,或者为什么它应该有用!