Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update a progress bar with howler js?

How can I use howler js and update the progress bar as the audio plays?

I assume I use either pos or seek however I can't seem to get it working.

Can I create a on event listener to change every time the position changes?

Progress bar HTML:

<progress id="progress_bar" value="0.0" max="1.0" style="-webkit-appearance: none; appearance: none; height: 48px; float: left;"></progress>

Howler js:

on ('update_progress', function() {
    document.getElementById('progress_bar').value = audio.pos();
}),

and then how can I update the position of the audio if the progress bar is pressed. I think I might actually be better served using an input range in that case.

like image 820
joshuatvernon Avatar asked Jun 10 '16 13:06

joshuatvernon


People also ask

How to create a basic progress bar using JavaScript?

To create a basic Progress Bar using JavaScript, the following steps needs to be carried out: Create HTML structure for your progress bar: The code below contains two “div” tag elements named “Progress_Status” and... Adding CSS: The code below is used to set the width and the background color of the ...

How to add labels to the progress bar?

Add Labels If you want to add labels to indicate how far the user is in the process, add a new element inside (or outside) the progress bar: Step 1) Add HTML: Example

How to access the <progress> element in HTML5?

The <progress> element can be accessed by using getElementById () method. level: It returns the list of progress bar. max: It is used to set or return the progress bar value of max attribute. value: It represent the amount of work are already completed.

How to use the progress object in HTML DOM?

The progress object in HTML DOM is used to represent the HTML <progress> element. The <progress> element can be accessed by using getElementById () method. level: It returns the list of progress bar. max: It is used to set or return the progress bar value of max attribute. value: It represent the amount of work are already completed.


1 Answers

There is currently no progress event in howler.js, though it may get added at a later date. However, you can get the current position by calling audio.seek() at any time (on 2.0) or audio.pos() on 1.0. You could then either call this in requestAnimationFrame (this is what the 2.0 demos use) or setInterval to update your progress bar.

like image 124
James Simpson Avatar answered Oct 01 '22 12:10

James Simpson