I am currently utilizing the waveSurfer library created by katspaugh for playing audio files.
In order to display 'elapsed time / total time', I have written code in the following manner:
waveSurfer.on('play', function() {
$scope.getCurrentDuration();
});
The $scope.getCurrentDuration()
function is designed to convert a floating-point variable into a string, as shown below:
$scope.getDuration = function() {
if ($scope.waveSurferReady) {
var time = waveSurfer.getDuration();
var minute = Math.floor(time / 60);
var tmp = Math.round(time - (minute * 60));
var second = (tmp < 10 ? '0' : '') + tmp;
return String(minute + ':' + second);
}
else {
return 'not ready yet';
}
};
However, I am facing an issue. When it comes to this part:
waveSurfer.on('play', function() ...)
the callback function is only triggered once.
I was expecting the callback function to be called periodically, but it seems to execute only once, resulting in the elapsed time being displayed only at the beginning.
How can I go about resolving this?