Node.js實現視頻路徑Blob加密

1、首先看下大廠的(愛奇藝)視頻的播放地址加密

Node.js實現視頻路徑Blob加密

紫霞仙子

2、Node.js實現(服務器端)

<code>let http = require('http');
let fs = require('fs');
let express = require('express');
let app = express();
/**
* 前端訪問頁面
*/
app.get('/', function(req, res) {
res.sendfile('./index.html') // 查看標題3前端頁面的index.html
})

/*
* 實現流傳送
*/
app.post('/', function(req, res) {
fs.createReadStream('./video.mp4') // 讀取當前目錄下的video.mp4視頻
.on("open",chunk=>{
console.log("chunk", chunk) // 準備好發送數據
})
.on("data",chunk=>{
console.log(chunk)
res.write(chunk); //發送數據
})
.on("end",()=>{
console.log('end')
res.end(); //發送結束
})
})
let port = 8008;
var server = http.createServer(app);
server.listen(port);
console.log('listening on port:' + port)/<code>

3、前端頁面(index.html)

<code>



<style><br> html, body {<br> margin: 0;<br> padding: 0;<br> width: 100%;<br> height: 100%;<br> text-align: center;<br> }<br> .video{<br> width: 384px;<br> height: 683px;<br> margin: 0 auto;<br> display: inline-block;<br> }<br> /<style>


<video>
\t
/<code>

4、實現效果

瀏覽器中輸入地址:http://localhost:8008/index.html 即可看到效果。

Node.js實現視頻路徑Blob加密

Node.js實現視頻地址Blob加密


分享到:


相關文章: