作者:isme7 | 来源:互联网 | 2023-05-19 16:06
1> Sam..:
如果您有源代码,则可以预先将数据预先下载到Javascript中的blob并在准备好时播放.
如果视频在您的服务器上,则以下内容应该有效.如果没有,您将遇到CORS问题.
var video = document.getElementById("Your video element id")
var url = "Some video url"
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.respOnseType= "arraybuffer";
xhr.Onload= function(oEvent) {
var blob = new Blob([oEvent.target.response], {type: "video/yourvideosmimmetype"});
video.src = URL.createObjectURL(blob);
//video.play() if you want it to play on load
};
xhr.Onprogress= function(oEvent) {
if (oEvent.lengthComputable) {
var percentComplete = oEvent.loaded/oEvent.total;
// do something with this
}
}
xhr.send();