Matrym
Matrym

Reputation: 17053

XMLHttpRequest for Video Tag?

Has anyone tried using binary data from an XHR request to be the content of a video file?

Upvotes: 2

Views: 2993

Answers (1)

Eli Grey
Eli Grey

Reputation: 35830

In Blob-supporting browsers, you can do the following and use a generate, given req is a 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);

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

Upvotes: 1

Related Questions