D-side, prompted to look in the direction of MediaSource . This object allows you to set the video object's url as window.URL.createObjectURL(mediaSource) . This allows you to set the source as a Blob, but with one important property: we can reload data into the mediaSource , for example, when receiving a continuation of video via AJAX or in some other way.
Example of working with MDN:
var video = document.querySelector('video'); var assetURL = 'frag_bunny.mp4'; var mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'; if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) { var mediaSource = new MediaSource; video.src = URL.createObjectURL(mediaSource); mediaSource.addEventListener('sourceopen', sourceOpen); } else { console.error('Unsupported MIME type or codec: ', mimeCodec); } function sourceOpen (_) { var mediaSource = this; var sourceBuffer = mediaSource.addSourceBuffer(mimeCodec); fetchData(assetURL, function (buf) { sourceBuffer.addEventListener('updateend', function (_) { mediaSource.endOfStream(); video.play(); }); sourceBuffer.appendBuffer(buf); }); };
The method is working, but there are some jokes, for example, 'video / mp4; codecs = "avc1.42E01E, mp4a.40.2" 'is the only Maym codec that works in both Chrome and Mozilla. If you want to work with webm: 'video / webm; codecs = "vp9, vorbis" 'in Mozilla, you will have to include the flag in about: config, which is not very pleasant for the user.
MediaSource? - D-side