XHR to download videos

Without going into the details of why I use XHR, can someone tell me how to make below work? My goal is to download the video data first and then put it in the source of the video library.

http://jsfiddle.net/u2vhG/

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
window.onload = function() {
    var elem = document.getElementById("myVideo");
    var req = new XMLHttpRequest();
    req.onload = function () {
        var blob_uri = URL.createObjectURL(this.response);
        elem.appendChild(document.createElement("source"))
            .src = blob_uri;
    };
    req.responseType = "blob";
    req.open('GET', 'http://www.latentmotion.com/player/h264/clips/16154_2832659676_170_180.mp4', false);
    req.send(null);
};
</script>
</head>
<body>
<video id="myVideo" width="600" height="334" controls></video>
</body>
</html>
+3
source share
2 answers

Refer to the workaround for Google Chrome until responseType = "blob" is implemented.

- I, answering the same question.

If you read my answer and link, you will see that Google Chrome does not actually support it responseType = "blob". I gave you a hypothetical implementation and connected you with a workaround with help responseType = "arraybuffer".

+1
source

,

  • req.responseType = "blob"; req.open(...)
  • , - .

URL.revokeObjectURL URL. , Chrome webkitURL, URL.

0

All Articles