How can I set preview of video file, selecting from input type='file'

后端 未结 5 2040
栀梦
栀梦 2020-12-01 00:32

In one of my module, I need to browse video from input[type=\'file\'], after that I need to show selected video before starting upload.

I am using basic HTML tag to

5条回答
  •  鱼传尺愫
    2020-12-01 01:31

    @FabianQuiroga is right that you should better use createObjectURL than a FileReader in this case, but your problem has more to do with the fact that you set the src of a element, so you need to call videoElement.load().

    $(document).on("change", ".file_multi_video", function(evt) {
      var $source = $('#video_here');
      $source[0].src = URL.createObjectURL(this.files[0]);
      $source.parent()[0].load();
    });
    
    
    
    
    

    Ps: don't forget to call URL.revokeObjectURL($source[0].src) when you don't need it anymore.

提交回复
热议问题