easywasmplayer文件地址:https://www.npmjs.com/package/easywasmplayer
一:介紹
EasyPlayer.js H5播放器,是一款能夠同時支援HTTP、RTMP、HTTP-FLV、HLS(m3u8)影片直播與影片點播等多種協議,支援H.264、H.265、AAC等多種音影片編碼格式,支援mse、wasm等多種解碼方式,支援Windows、Linux、Android、iOS全平臺終端的H5播放器。
二:html+js實現影片流播放
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EasyWasmPlayer-Demo</title>
<script src="./EasyWasmPlayer.js"></script>
<style>
.box {
width:600px;
height:400px;
}
</style>
</head>
<body>
<div class="box">
<div id="Player"></div>
</div>
<script>
// 例項化播放器
var Player = new WasmPlayer(null,'Player',callbackFun,{cbUserPtr:this, decodeType:"auto", openAudio:1, BigPlay:false, Height:true});
// 呼叫播放
Player.play('影片流地址', 1);
//播放事件回撥
function callbackFun(e) {
console.log(e)
}
</script>
</body>
</html>
三:vue實現影片流播放
1:安裝easywasmplayer
npm install @easydarwin/easywasmplayer --save
2:複製
將@easydarwin/easywasmplayer/EasyWasmPlayer.js和@easydarwin/easywasmplayer/libDecoder.wasm複製到專案public目錄下
3:在public目錄下的index.html引入easywasmplayer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title>EasyWasmPlayer-Demo</title>
<script src="./EasyWasmPlayer.js"></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
4:使用easywasmplayer實現影片流播放
<template>
<div class="box">
<div id="Player"></div>
</div>
</template>
<script>
export default {
data() {
return {
player: '',
url: '影片流地址'
}
},
mounted() {
// 例項化播放器
this.player = new WasmPlayer(null, 'Player', this.callbackfun)
// 呼叫播放
this.player.play(this.url, 1)
},
methods: {
//播放事件回撥
callbackfun(e) {
console.log('callbackfun', e);
}
}
}
</script>
<style>
.box {
width:600px;
height:400px;
}
</style>