vue3 項目 用 vue-video-player 做直播 ( 親測可用 )


npm 安裝

npm install --save vue-video-player

npm install --save videojs-flash

 

 

 1 <template>
 2   <section class="video-box">
 3     <videoPlayer
 4       ref="videoPlayer"
 5       :options="videoOptions"
 6       class="vjs-custom-skin videoPlayer"
 7       :playsinline="true"
 8     />
 9   </section>
10 </template>
11 <script>
12   import 'video.js/dist/video-js.css'
13   import 'vue-video-player/src/custom-theme.css'
14   import { videoPlayer } from 'vue-video-player'
15   import 'videojs-flash'
16   export default {
17     components: {
18       videoPlayer
19     },
20     data () {
21       return {
22         videoSrc: '',
23         // 視頻播放
24         videoOptions: {
25           playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
26           autoplay: false, //如果true,瀏覽器准備好時開始回放。
27           muted: false, // 默認情況下將會消除任何音頻。
28           loop: false, // 導致視頻一結束就重新開始。
29           preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應該開始下載視頻數據。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)
30           language: 'zh-CN',
31           aspectRatio: '16:9', // 將播放器置於流暢模式,並在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3")
32           techOrder: ['flash', 'html5'],      // 兼容順序
33           sources: [{ // 流配置,數組形式,會根據兼容順序自動切換
34             type: 'rtmp/hls',
35             src: 'rtmp://58.200.131.2:1935/livetv/hunantv'
36           }],
37           poster: "", //你的封面地址
38           // width: document.documentElement.clientWidth,
39           notSupportedMessage: '此視頻暫無法播放,請稍后再試', // 允許覆蓋Video.js無法播放媒體源時顯示的默認信息。
40           controlBar: {
41             timeDivider: true,
42             durationDisplay: true,
43             remainingTimeDisplay: false,
44             fullscreenToggle: true  //全屏按鈕
45           }
46         }
47       }
48     }
49   }
50 </script>
51 <style scoped>
52   .video-box {
53     width: 1000px;
54     padding: 20px;
55   }
56 </style>

 

最后,這是 rtmp 流的測試網址:https://willarun365.blog.csdn.net/article/details/109180771#comments_14708186 

 

安裝完了之后沒播放視頻也沒報錯別慌,安裝一波:https://www.flash.cn/  ( 針對前端開發用的谷歌瀏覽器不能播放的問題,安裝完了插件之后瀏覽器允許這個插件使用,然后你就能進入測試階段( 在老板面前光明正大的直播,記得開F12假裝測試在測試功能 ) )

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM