网络文件路径转换为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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值