網絡文件路徑轉換爲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

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