廢話少說,直接上效果,看代碼
<body>
<video id="sound" width="200" controls="controls"></video>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('#sound').bind('contextmenu',function() { return false; });//禁止js右鍵,防下載
//創建XMLHttpRequest對象
var xhr = new XMLHttpRequest();
//配置請求方式、請求地址以及是否同步
xhr.open('GET', 'http://localhost:3000/', true);
//設置請求結果類型為blob
xhr.responseType = 'blob';
//請求成功回調函數
xhr.onload = function(e) {
? ? if (this.status == 200) {//請求成功
? ? ? ? //獲取blob對象
? ? ? ? var blob = this.response;
? ? ? ? //隱藏真實地址
? ? ? ? $("#sound").attr("src", URL.createObjectURL(blob));
? ? }
};
xhr.send();
})