Próbuję uruchomić funkcję, gdy zakończy się dźwięk. Używam tej funkcji do tworzenia dźwięku.
function sound(src,volume,repeat) {
volume = volume || 1
repeat = repeat || false;
this.sound = document.createElement("audio");
this.sound.volume = volume;
this.sound.src = src;
this.sound.setAttribute("preload", "");
this.sound.setAttribute("class", "gamesound");
if(repeat)this.sound.setAttribute("loop","");
this.sound.style.display = "none";
document.body.appendChild(this.sound);
this.play = function(){
this.sound.play();
}
this.stop = function(){
this.sound.pause();
}
this.pause = function(){
this.sound.pause();
}
this.onend = function (s){
this.sound.onended = s;
}
this.load = function(){
this.sound.load();
}
this.currentTime = function (t){
this.sound.currentTime = t;
}
}
Więc może być używany w ten sposób
var song = new sound("sound.mp3",0.2,true);
song.ended(function(){
alert("ended");
})
Ale to nie jest wyzwalanie, gdzie ja się tu mylę.
Odpowiedzi:
0 dla odpowiedzi № 1Zdarzenie nie zostanie wyrzucone, jeśli masz włączoną opcję pętli, którą właśnie przedstawiasz.