Trying to get full video duration but returning as Nan
Wait for onloadedmetadata
event, The loadedmetadata
event is fired when the metadata has been loaded.
var myVideo = document.getElementById("videoPlayerNew");
myVideo.onloadedmetadata = function() {
console.log('metadata loaded!');
console.log(this.duration);//this refers to myVideo
};
<video id="videoPlayerNew" class="video-js vjs-default-skin vjs-controls-enabled" poster="http://camendesign.com/code/video_for_everybody/poster.jpg" data-setup="{}" controls="">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<p class="vjs-no-js">Javascript was disabled or not supported</p>
</video>
Try this code below, it adds the event after everything is loaded :
$(document).ready(function(){
$("#videoPlayerNew").on( "timeupdate", function(event){
console.log( this.duration);
});
});