Wondering if Howler JS has a way of notifying every second? This would be used to update a state variable that tracks how long a song has been playing for. One way to do it is like this:
var sound = new Howl({
xhr: {
method: 'POST',
headers: {
Authorization: 'Access-Control-Allow-Origin:*',
},
withCredentials: true,
},
// autoplay: true,
loop: true,
volume: 1,
format: ['mp3'],
src: [mp3],
});
sound.play();
let position: number = 0;
const s = interval(1000).subscribe((v) => {
console.log(v);
if (!sound.playing()) {
s.unsubscribe();
}
position = sound.seek();
console.log(position);
Just curious if howler has something like:
const interval = 1000;
song.on(interval, callback)
So that would call the callback until the song is done playing?
As stated in the docs,
Howlerinstances have a method.onto listen to events. Sadly, there is no progression event or similar.However, there is an option
html5that can be set totruein order to force the use of HTML5 for playback.A call to
Howler#playreturns theSound's ID. In your case:You can get the
Soundobject by callingHowler#_soundById.You can get the HTML5 audio element by using the
Sound#_nodeproperty (which will be anHTMLAudioElement).Then you can use whatever
HTMLAudioElementprovides, including listening toprogressevents.