javascript - Get Video Duration jQuery -
i have question. trying duration of source.
i want next: when page load need duration of source problem when want duration apparently not visible, can duration when press button. need know duration since start because need calculate position on video/audio , send through currenttime.
i try "alert" result "nan".
this 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.
you'll have wait @ least until metadata loaded videos duration, luckily there's event that
$( document ).ready(function() { var asset = $('#asset')[0]; // obtiene el objeto var tipo = $('#asset').attr('class'); // video, audio, pdf var duracion = 0; var tiempo = 0; var porcentaje = $('#porcentaje').data('percent'); asset.addeventlistener('loadedmetadata', function() { duracion = asset.duration; tiempo = (porcentaje*duracion)/100; asset.currenttime = tiempo; }); $("#guardar").click(function() { var avance = asset.currenttime; if(tipo == 'video' || tipo == 'audio'){ porcentaje = parseint((avance*100)/duracion); } else if(tipo == 'pdf') { porcentaje = 100; } }); });
Comments
Post a Comment