网络文件路径转换为blob路径

const xhr = new XMLHttpRequest();
xhr.open("get", 'https://dss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=2810627290,1080409091&fm=58&s=8197C732C535FA313E526557030030BB&bpow=121&bpoh=75');
xhr.responseType = "blob"; // ""|"text"-字符串 "blob"-Blob对象 "arraybuffer"-ArrayBuffer对象
xhr.onload = function() {
    //blob://file:///xxxxxxxxxxxxxxxxxxxxx
    var path=URL.createObjectURL(xhr.response)
    alert(path)
};
xhr.send();

 

HTML5 Video 使用 Blob

//创建XMLHttpRequest对象
var xhr = new XMLHttpRequest();

//配置请求方式、请求地址以及是否同步
xhr.open('POST', '视频路径', true);

//设置请求结果类型为blob
xhr.responseType = 'blob';

//请求成功回调函数
xhr.onload = function(e) {
    if (this.status == 200) {//请求成功
        //获取blob对象
        var blob = this.response;
        //获取blob对象地址,并把值赋给容器
        $("#player").attr("src", URL.createObjectURL(blob));
    }
};
xhr.send();


HTML:
<video id="player" width="200" controls="controls"></video>

 

推荐文章:

MediaSource的使用以及封装MP4转加载Blob的插件

http://www.ptbird.cn/javascript-mediasource-mpt-to-blob.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章