获取视频mp4格式的网址,并使用blob src显示视频

时间:2019-05-06 11:49:06

标签: jquery html html5-video blob

我想从URL获取mp4视频文件并以Blob格式的视频src显示它。我找到了一个从输入文件类型获取文件的示例代码。我想更改它并从URL获取视频。你能帮我吗

这是我的示例代码

    <input type="file" id="fileinput"/>
    <video id="video" width="200" height="200" controls />

<script>
function readSingleFile(evt) {
   var video=document.getElementById('video')
    //Retrieve the first (and only!) File from the FileList object
    var f = evt.target.files[0]; 

    if (f) {
      var r = new FileReader();
      r.onload = function(e) { 
          var contents = e.target.result;
      /*   console.log( "Got the file.n" 
              +"name: " + f.name 

        );  */
/*         var blob = new Blob([this.result], {type: 'application/octet-stream'}); */
        var uint8Array  = new Uint8Array(contents);

var arrayBuffer = uint8Array.buffer;
var blob        = new Blob([arrayBuffer]);
        console.log(uint8Array)

          video.src = URL.createObjectURL(blob);


          console.log(contents)
      /*   video.src=contents */
      }
      r.readAsArrayBuffer(f);

    } else { 
      alert("Failed to load file");
    }
  }

  document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
</script>

0 个答案:

没有答案