Reputation:
I'm trying to use the Howler on end method to update some properties after a track finishes, but it's not working properly. Code like this:
var track_number = 0;
var sound = new Howl({
src: ["barking.mp3"],
autoplay: false;
volume: 0.5;
onload: function() {
console.log("LOADED");
}
});
sound.onend() {
track_number ++;
$("#xxxjukeboxpicture".attr("src", "/tile" + track_number + ".jpg");
};
Every time I try to add the sound.onend()
function in and run this the browser throws an error saying there is a missing semi-colon on the sound.onend()
line. Can someone clarify the correct syntax here?
Upvotes: 1
Views: 5858
Reputation: 6932
This is an old thread. But I have just been looking at howler..
The on events need to be part of the new howler object as optionals.
So the reason you get this error is because you are not adding onend as such but trying to add it independently. I assume sound.on('end'
works because it is using the browser API rather than Howler's.
The correct way for the options and events is:
var sound = new Howl({
src: ["barking.mp3"],
preload: true,
autoplay: false,
onload: function() {
console.log("LOADED");
},
onend: function() {
console.log("ONEND");
}
});
Upvotes: 4
Reputation: 952
You'll need to do the following:
sound.on('end', function(){
track_number ++;
$("#xxxjukeboxpicture".attr("src", "/tile" + track_number + ".jpg");
});
Based on Howler docs: https://github.com/goldfire/howler.js#documentation
Upvotes: 6