The creation in the HTML of the slider is this, I use a framework, the nouislider. The Slider is because I am creating a player with HTML and jQuery together with Bootstrap. The slider would have to work, logically, to advance as the audio plays.
<div id="slider" class="slider shor slider-success"> </div>
In the JS I have this:
var slider = document.getElementById('slider');
audio = document.getElementById('audio1');
$('#play1').click(function () {
if ($("#audio1").get(0).paused) {
$("#audio1").get(0).play();
document.getElementById('tempo_atual').innerHTML = secToStr( audio1.currentTime);
document.getElementById('tempo_total').innerHTML = secToStr( audio1.duration );
} else {
$("#audio1").get(0).pause();
}
});
audio.addEventListener('timeupdate', atualizar , false);
noUiSlider.create(slider, {
start: 0,
range: {
'min': 0,
'max': audio.duration
}
});
//slider1Value = document.getElementById('slider1-span'),
slider.noUiSlider.on('update', function( values, handle ){
//slider1Value.innerHTML = values[handle];
position = values[handle];
audio.currentTime = position;
});
function atualizar(){
document.getElementById('tempo_atual').innerHTML = secToStr( audio.currentTime);
document.getElementById('tempo_total').innerHTML = secToStr( audio.duration);
}
What I can think of is that in the function actualizar()
go something like this:
slider.noUiSlider.set(audio.currentTime);
BUT IT DOES NOT WORK FOR ME. Do I do it in the wrong place? Do I use the .set()
wrong?
How can I solve this problem?
Alvaro Montoro: Thanks for the corrections, it happens is my first time using Stack Overflow, in addition to writing everything in a hurry.