一、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>
三、效果图如下:
原文地址:https://www.cnblogs.com/phperlinxinlan/p/11317031.html
时间: 2024-10-04 19:58:15