【问题标题】:How to preview a video before upload - vanilla JavaScript no third-party libraries如何在上传前预览视频 - vanilla JavaScript 没有第三方库
【发布时间】:2020-05-19 09:32:52
【问题描述】:

如何在使用 vanilla JavaScript 上传到服务器之前显示视频?

<input type="file" onchange="loadFile(event)">
<video width="320" height="240" controls>
  <source id="output" type="video/mp4">
  Your browser does not support the video tag.
</video>

JavaScript:

function loadFile(){
    // Display chosen file in id "output"
}

【问题讨论】:

    标签: javascript html web


    【解决方案1】:

    const load = (e) => {
      let url = URL.createObjectURL(e.files[0])
      let video = document.querySelector("#id");
      video.setAttribute("src", url)
      video.play();
    }
    <input type="file" onChange="load(this)" />
    <video width="320" height="240" controls id="id">
    
    </video>

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 2021-02-17
      • 2019-02-02
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      相关资源
      最近更新 更多