<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          關于vue播放flv,m3u8視頻流(監控)的方法

          2023-4-19    前端達人

          前文:隨著前端大屏頁面的逐漸壯大,客戶的需求也越來越多,大屏上面展示的事物也越來越豐     富。其中實時播放監控的需求逐步增加,視頻流格式也是有很多種,用到最多的.flv、.m3u8。

          一、 JessibucaPlayer插件用來播放flv流

          1.首先是先把文件放在vue項目的public下面

          2.在index.html文件里面引入 index.js文件(直接引入即可)

           3.把封裝好的JessibucaPlayer組件放到公共components

          
          
          1. <template>
          2. <div class="jessibuca-player" style="width: 100%; height: 100%">
          3. <div class="container" :id="id" ref="container"></div>
          4. </div>
          5. </template>
          6. <script>
          7. export default {
          8. name: "JessibucaPlayer",
          9. props: {
          10. videoUrl: {
          11. type: String,
          12. default: ""
          13. },
          14. id: {
          15. type: Number,
          16. required: true
          17. }
          18. },
          19. data() {
          20. return {
          21. jessibuca: null // jessibuca 實例化對象
          22. };
          23. },
          24. methods: {
          25. init() {
          26. this.jessibuca = new window.Jessibuca({
          27. container: document.getElementById(this.id), // 播放器容器,若為 string ,則底層調用的是 document.getElementById('id')
          28. videoBuffer: 0.2, // 設置最大緩沖時長,單位毫秒,播放器會自動消除延遲。
          29. forceNoOffscreen: true, // 是否不使用離屏模式(提升渲染能力)
          30. hasAudio: false, // 是否有音頻
          31. rotate: 0, // 設置旋轉角度,只支持,0(默認) ,180,270 三個值
          32. isResize: false, // 1.當為true的時候:視頻畫面做等比縮放后,高或寬對齊canvas區域,畫面不被拉伸,但有黑邊;2.當為false的時候:視頻畫面完全填充canvas區域,畫面會被拉伸
          33. isFullSize: true, // 當為true的時候:視頻畫面做等比縮放后,完全填充canvas區域,畫面不被拉伸,沒有黑邊,但畫面顯示不全
          34. debug: false, // 是否開啟控制臺調試打印
          35. timeout: 30, // 設置超時時長, 單位秒,在連接成功之前和播放中途,如果超過設定時長無數據返回,則回調timeout事件
          36. supportDblclickFullscreen: true, // 是否支持屏幕的雙擊事件,觸發全屏,取消全屏事件。
          37. showBandwidth: false, // 是否顯示網速
          38. operateBtns: {
          39. // 配置功能
          40. fullscreen: false, // 是否顯示全屏按鈕
          41. screenshot: false, // 是否顯示截圖按鈕
          42. play: false, // 是否顯示播放暫停按鈕
          43. audio: false // 是否顯示聲音按鈕
          44. },
          45. keepScreenOn: false, // 開啟屏幕常亮,在手機瀏覽器上, canvas標簽渲染視頻并不會像video標簽那樣保持屏幕常亮。
          46. isNotMute: false, // 是否開啟聲音,默認是關閉聲音播放的。
          47. loadingText: "加載中...", // 加載過程中文案。
          48. background: "" // 背景圖片。
          49. });
          50. // 事件:
          51. this.jessibuca_load()
          52. // 1. 監聽 jessibuca 初始化事件。
          53. this.jessibuca.on("load", () => {
          54. this.jessibuca_load()});
          55. // 2. 信息,包含錯誤信息
          56. this.jessibuca.on("log", data => this.jessibuca_log(data));
          57. // 3. 觸發暫停事件
          58. this.jessibuca.on("pause", this.jessibuca_pause);
          59. // 4. 觸發播放事件
          60. this.jessibuca.on("play", this.jessibuca_play);
          61. // 5. 當前是否全屏
          62. this.jessibuca.on("fullscreen", this.jessibuca_fullscreen);
          63. // 6. 觸發聲音事件,返回boolean值
          64. this.jessibuca.on("mute", this.jessibuca_mute);
          65. // 7. 當解析出音頻信息時回調
          66. this.jessibuca.on("audioInfo", this.jessibuca_audioInfo);
          67. // 8. 當解析出視頻信息時回調
          68. this.jessibuca.on("videoInfo", this.jessibuca_videoInfo);
          69. // 9. 錯誤信息
          70. this.jessibuca.on("error", this.jessibuca_error);
          71. // 10. 當設定的超時時間內無數據返回,則回調
          72. this.jessibuca.on("timeout", this.jessibuca_timeout);
          73. // 11. 流狀態統計,流開始播放后回調,每秒1次
          74. this.jessibuca.on("start", this.jessibuca_start);
          75. // 12. 渲染性能統計,流開始播放后回調,每秒1次
          76. this.jessibuca.on("performance", this.jessibuca_performance);
          77. // 13. 當前網速, 單位KB 每秒1次,
          78. this.jessibuca.on("kBps", this.jessibuca_kBps);
          79. },
          80. // 事件:
          81. jessibuca_load() {
          82. // 監聽 jessibuca 初始化事件。
          83. console.log("on load");
          84. console.log("module", this.videoUrl);
          85. this.methods_play(this.videoUrl);
          86. },
          87. jessibuca_log(data) {
          88. // 信息,包含錯誤信息
          89. console.log("on log", data);
          90. },
          91. jessibuca_pause(flag) {
          92. // 觸發暫停事件
          93. console.log("on pause", flag);
          94. },
          95. jessibuca_play(flag) {
          96. // 觸發播放事件
          97. console.log("on play", flag);
          98. },
          99. jessibuca_fullscreen(flag) {
          100. // 當前是否全屏
          101. console.log("on fullscreen", flag);
          102. if (flag) {
          103. let myEvent = new Event("resize");
          104. setTimeout(() => {
          105. window.dispatchEvent(myEvent);
          106. }, 100);
          107. }
          108. },
          109. jessibuca_mute(flag) {
          110. // 觸發聲音事件
          111. console.log("on mute", flag);
          112. },
          113. jessibuca_audioInfo(data) {
          114. // 當解析出音頻信息時回調,2個回調參數
          115. // 1. numOfChannels:聲頻通道
          116. // 2. sampleRate 采樣率
          117. console.log("audioInfo", data);
          118. },
          119. jessibuca_videoInfo(data) {
          120. // 當解析出視頻信息時回調
          121. // 1. w:視頻寬
          122. // 2. h:視頻高
          123. console.log("videoInfo", data);
          124. },
          125. jessibuca_error(error) {
          126. // 錯誤信息
          127. console.log("error:", error);
          128. },
          129. jessibuca_timeout() {
          130. // 當設定的超時時間內無數據返回,則回調
          131. console.log("timeout");
          132. },
          133. jessibuca_start(s) {
          134. // 流狀態統計,流開始播放后回調,每秒1次
          135. // 1. buf: 當前緩沖區時長,單位毫秒
          136. // 2. fps: 當前視頻幀率,
          137. // 3. abps: 當前音頻碼率,單位bit,
          138. // 4. vbps: 當前視頻碼率,單位bit,
          139. // 5. ts:當前視頻幀pts,單位毫秒
          140. // console.log('stats is', s);
          141. },
          142. jessibuca_performance(performance) {
          143. // 渲染性能統計,流開始播放后回調,每秒1次。
          144. // 0: 表示卡頓、1: 表示流暢、2: 表示非常流程
          145. // console.log('performance', performance);
          146. },
          147. jessibuca_kBps(kBps) {
          148. // 當前網速, 單位KB 每秒1次,
          149. // console.log('kBps', kBps);
          150. },
          151. // 方法:
          152. methods_play(url) {
          153. // 播放
          154. if (this.jessibuca.hasLoaded()) {
          155. this.jessibuca.play(url);
          156. } else {
          157. console.error("視頻數據未加載完畢,請稍后操作");
          158. }
          159. },
          160. methods_mute() {
          161. // 靜音
          162. this.jessibuca.mute();
          163. },
          164. methods_cancelMute() {
          165. // 取消靜音
          166. this.jessibuca.cancelMute();
          167. },
          168. methods_pause() {
          169. // 暫停
          170. this.jessibuca.pause();
          171. },
          172. methods_setVolume(volume) {
          173. // 設置音量
          174. this.jessibuca.setVolume(volume);
          175. },
          176. methods_setRotate(rotate) {
          177. // 設置旋轉角度 0\180\270
          178. this.jessibuca.setRotate(rotate);
          179. },
          180. methods_destroy() {
          181. // 關閉視頻,釋放底層資源
          182. if (this.jessibuca) {
          183. this.jessibuca.destroy();
          184. }
          185. },
          186. methods_fullscreen(flag) {
          187. // 全屏(取消全屏)播放視頻
          188. this.jessibuca.setFullscreen(flag);
          189. },
          190. methods_screenShot() {
          191. // 截圖
          192. // 1. screenshot(filename, format, quality)
          193. // 2. {string} filename、 {string} format、{number} quality
          194. // 3.filename: 保存的文件名, 默認 時間戳、format : 截圖的格式,可選png或jpeg或者webp ,默認 png、quality: 可選參數,當格式是jpeg或者webp時,壓縮質量,取值0 ~ 1 ,默認 0.92
          195. this.jessibuca.screenshot();
          196. },
          197. methods_setBufferTime(time) {
          198. // 設置最大緩沖時長,單位秒,播放器會自動消除延遲。
          199. // {number} time
          200. this.jessibuca.setBufferTime(Number(time));
          201. },
          202. methods_setScaleMode(mode) {
          203. // 設置播放器填充
          204. // 1. 0 視頻畫面完全填充canvas區域,畫面會被拉伸 等同于參數 isResize 為false
          205. // 2. 1 視頻畫面做等比縮放后,高或寬對齊canvas區域,畫面不被拉伸,但有黑邊 等同于參數 isResize 為true
          206. // 3. 2 視頻畫面做等比縮放后,完全填充canvas區域,畫面不被拉伸,沒有黑邊,但畫面顯示不全 等同于參數 isFullSize 為true
          207. this.jessibuca.setScaleMode(Number(mode));
          208. },
          209. restartPlay() {
          210. // 重新加載
          211. this.methods_destroy();
          212. this.methods_play(this.videoUrl);
          213. }
          214. },
          215. mounted() {
          216. this.init();
          217. window.onerror = msg => (this.err = msg);
          218. },
          219. beforeDestroy() {
          220. if (this.jessibuca) this.jessibuca.destroy();
          221. }
          222. };
          223. </script>
          224. <style>
          225. @import url("./JessibucaPlayer.css");
          226. </style>

           4.最后再自己用到的文件里面 引入組件即可

           如有想要文件的請私聊

          二、easyplayer插件播放m3u8流

          教程:

          1.首先npm安裝EasyPlayer、copy-webpack-plugin
          ps:copy-webpack-plugin版本一定一定一定不能大于6.0,否則會報錯。

          
          
          1. npm install @easydarwin/easyplayer --save
          2. npm install copy-webpack-plugin@5.1.2 --save-dev

          2.最重要的地方 一定要把這個地方弄好 那就是在vue.config.js里面

          
          
          1. const CopyWebpackPlugin = require('copy-webpack-plugin')
          2. configureWebpack: {
          3. plugins:[
          4. new CopyWebpackPlugin([
          5. {
          6. from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.swf',
          7. to: './libs/EasyPlayer/'
          8. },
          9. {
          10. from: 'node_modules/@easydarwin/easyplayer/dist/component/crossdomain.xml',
          11. to: './libs/EasyPlayer/'
          12. },
          13. {
          14. from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer-lib.min.js',
          15. to: './libs/EasyPlayer/'
          16. }
          17. ])
          18. ]
          19. }

          3.還需要在public/index.html 引入EasyPlayer-lib.min.js,可以直接在node_modules里找到@easydarwin下的dist/compent/EasyPlayer-lib.min.js復制到pubilc目錄下,還有需要EasyPlayer.wasm同樣放到public目錄下

           4.引入組件使用

           最后效果



          藍藍設計建立了UI設計分享群,每天會分享國內外的一些優秀設計,如果有興趣的話,可以進入一起成長學習,請加微信ban_lanlan,報下信息,藍小助會請您入群。歡迎您加入噢~~
          希望得到建議咨詢、商務合作,也請與我們聯系01063334945。 

          分享此文一切功德,皆悉回向給文章原作者及眾讀者. 免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。 

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務、UI設計公司、界面設計公司、UI設計服務公司、數據可視化設計公司、UI交互設計公司、高端網站設計公司、UI咨詢、用戶體驗公司、軟件界面設計公司

          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合