XMLHttpRequest for video tags?

Has anyone tried to use binary data from an XHR request as the contents of a video file?

+2
source share
1 answer

In Blob-supporting browsers , you can do the following and use the generated file specified reqis new XMLHttpRequest:

var some_video_element = ...;
req.onload = function () {
    var blob_uri = URL.createObjectURL(this.response);
    some_video_element.appendChild(document.createElement("source"))
        .src = blob_uri;
};
req.responseType = "blob";
req.open(...);
req.send(null);

See the workaround for Google Chrome before responseType = "blob".

+1
source

All Articles