Search code examples
javascriptjqueryaudiosyntax-errorhowler.js

Correct way to call Howler onend() method


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?


Solution

  • 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