廢話少說(shuō),直接上效果,看代碼

<body>
<video id="sound" width="200" controls="controls"></video>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('#sound').bind('contextmenu',function() { return false; });//禁止js右鍵,防下載
//創(chuàng)建XMLHttpRequest對(duì)象
var xhr = new XMLHttpRequest();
//配置請(qǐng)求方式、請(qǐng)求地址以及是否同步
xhr.open('GET', 'http://localhost:3000/', true);
//設(shè)置請(qǐng)求結(jié)果類型為blob
xhr.responseType = 'blob';
//請(qǐng)求成功回調(diào)函數(shù)
xhr.onload = function(e) {
? ? if (this.status == 200) {//請(qǐng)求成功
? ? ? ? //獲取blob對(duì)象
? ? ? ? var blob = this.response;
? ? ? ? //隱藏真實(shí)地址
? ? ? ? $("#sound").attr("src", URL.createObjectURL(blob));
? ? }
};
xhr.send();
})