Im playing some HTML5 sound using the Howler.js library.
Currently, they have been able to determine the total length of the audio file using sound.duration();, however, I'm not sure how to create a timer to show how much time has been played.
I create a simple sound object:
var sound = new Howl({
src: ['sound.ogg', 'sound.mp3', 'sound.wav'],
autoplay: true,
loop: false,
volume: 1,
onload: function() {
var totalSoundDuration = sound.duration();
},
onplay: function(getSoundId) {
},
onend: function() {
}
});
I cannot find any method in the library (?) To check currentTime so that I can update the timer function.
An alternative route might just be to start / switch setInterval to onplay:like:
var currentTimeTracker=setInterval(function () {myTimer()}, 1000);
function myTimer() {
timePlayed++;
$("#time" ).html(timePlayed);
}
Not sure if this will be a good approach? Any suggestions?
Howler.js ref:
https://github.com/goldfire/howler.js/tree/2.0#global-core-properties