I have a question. I am trying to get the duration of a source.
I want to do the next: When the page load i need to get the duration of the source but the problem is that when i want to get the duration apparently is not visible, only i can get the duration when i press a button. I need to know the duration since the start because i need to calculate a position on video/audio and send through currentTime.
I try to do "alert" but the result is "NaN".
This is my code actually:
$( document ).ready(function() {
var asset = $('#asset')[0]; // Obtiene el Objeto
var tipo = $('#asset').attr('class'); // Video, Audio, PDF
var duracion = asset.duration;
var porcentaje = $('#porcentaje').attr('data-percent');
var tiempo = (porcentaje*duracion)/100;
asset.currentTime = tiempo;
alert(duracion); // NaN
$("#guardar").click(function() {
var avance = asset.currentTime;
if(tipo == 'video' || tipo == 'audio'){
porcentaje = parseInt((avance*100)/duracion);
}
else if(tipo == 'pdf'){
porcentaje = 100;
}
alert(porcentaje);
});
});
That's all. Thank you.
Gustavo G.