javascript实现blob加密视频源地址
程序员文章站
2022-07-11 18:59:01
一、HTML代码: 二、JavaScript代码: 三、效果图如下: ......
一、html代码:
<video id="my-video" class="video-js" playsinline controls preload="auto" controlslist="nodownload" controlslist="nofullscreen" width="100%" height="240" poster="upload/moviepic/2019-08-02/1564739500xyzp.png" data-setup="{}"> <source src="" type="video/mp4"> <source src="" type="video/ogg"> <source src="" type="video/webm"> <p class="vjs-no-js"> to view this video please enable javascript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports html5 video</a> </p> </video>
二、javascript代码:
<script type="text/javascript"> var video = document.getelementbyid("my-video"); window.url = window.url || window.webkiturl; var xhr = new xmlhttprequest(); var play_url = 'test.mp4'; xhr.open("get", play_url, true); xhr.responsetype = "blob"; xhr.onload = function() { if (this.status == 200) { var blob = this.response; console.log(blob); video.onload = function(e) { window.url.revokeobjecturl(video.src); }; video.src = window.url.createobjecturl(blob); } } xhr.send(); </script>
三、效果图如下: