dimanche 1 mars 2015

Audio seek bar in JS using slider


I have a slider in html,



<div id="seekslider" style="width: 75%; margin: 0 auto; margin-top: 10px; display: inline-block;"></div>


and I want it to move as the audio plays, and also be 'seek-able.'


I know I'm doing something wrong.. Here's the mess I have so far:



function intializePlayer(){
audio = document.getElementById("player");
playbtn = document.getElementById("controlTogglePlay");
seekslider = document.getElementById("seekslider");
playbtn.addEventListener("click",playPause,false);
seekslider.addEventListener("change",audioSeek,false);
audio.addEventListener("timeupdate",seektimeupdate,false);
seekslider = $("#seekslider");
seekslider.slider({
orientation: "horizantal",
value: 25,
range: "min",
min: 0,
max: 100,
step: 1,
slide: function(event, ui) {
$("#seekslider.value").prop("seekslider", ui.value / 100);
updateCookies();
}
});
}

window.onload = intializePlayer;

function audioSeek(){
var seekto = audio.duration * (seekslider.value / 100);
audio.currentTime = seekto;
}
function seektimeupdate(){
var nt = audio.currentTime * (100 / audio.duration);
seekslider.value = nt;
}


What am I doing wrong?





Aucun commentaire:

Enregistrer un commentaire