Using jQuery to determine video file size

后端 未结 4 506
遇见更好的自我
遇见更好的自我 2021-01-18 09:37

I am using videojs to play html5 videos, of varying dimensions. Is it possible to detect the height/width of a video file using jQuery (or another scripting language for th

4条回答
  •  天涯浪人
    2021-01-18 09:52

    Yes, you can get the videoWidth and videoHeight properties - they are downloaded with the video's metadata, so be sure not to use preload="none" with your video element as it prevents metadata from being downloaded until someone tries to play the video. Here's how to do it with jquery:

    $(function(){
      $('video').bind('loadedmetadata', function(){
        var rawWidth = $(this).prop('videoWidth');
        var rawHeight = $(this).prop('videoHeight');
      });
    });
    

提交回复
热议问题