0
Ich versuche eine Funktion zu aktivieren, wenn das Audio beendet ist. Ich verwende diese Funktion, um den Sound zu erstellen.JS Audio aktiviert nicht, wenn Audio endet
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;
}
}
So kann es wie dieses
var song = new sound("sound.mp3",0.2,true);
song.ended(function(){
alert("ended");
})
verwendet werden, aber es ist nicht Auslösung, wo gehe ich hier falsch.
Sehen Sie, ich wusste, es war etwas dummes. Danke @Yousef – MasterT