I'm just trying to update a simple progress bar on time update, so I'm doing this:
var audioFile = thisPlayerBtn.attr('audioFile');
var audioFilePlayer = document.createElement('audio');
audioFilePlayer.setAttribute('src', audioFile);
audioFilePlayer.setAttribute('id', 'theAudioPlayer');
audioFilePlayer.load();
$.get();
audioFilePlayer.addEventListener("load", function() {
audioFilePlayer.play();
}, true);
$('#hiddenAudioElements').append(audioFilePlayer);
audioFilePlayer.play();
audioFilePlayer.bind('timeupdate', updateTime);
var updateTime = function(){
var thisPlayer = $(this);
var widthOfProgressBar = Math.floor( (100 / thisPlayer.duration) * thisPlayer.currentTime);
$('#songIdForPorgessBar').css({
'width':widthOfProgressBar+'%'
});
}
Firebug says that "bind" is not a function, so I swapped it with "addEventListener" and I get no error but the progress bar doe not update.
Not sure what I'm doing wrong or if there's a better way of going about it. Here is my fiddle: http://jsfiddle.net/j44Qu/ it works, plays the audio, just doesn't update the progress bar and I'm stumped.
Your problem is that you're using jQuery objects when you should be using dom nodes and vice versa.
bind
is a jQuery method yet you call it on the audio node
$(audioFilePlayer).bind('timeupdate', updateTime);
duration
and currentTime
are audio node properties but you try to reference them from a jQuery object
var widthOfProgressBar = Math.floor( (100 / this.duration) * this.currentTime);
http://jsfiddle.net/j44Qu/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With