在vue中接收rtmp視頻流並播放,切換視頻源


vue環境

1、包

"video.js": "5.19",
 "videojs-flash": "2.1.2"

2、html

<video
                id="my-player1"
                class="video-js
                vjs-default-skin
                vjs-big-play-centered"
                preload="auto"
                width="500"
                height="400"
                data-setup='{ "html5" : { "nativeTextTracks" : false } }'>
               
              </video>

 

3、js

data里放

options1: {
          autoplay: true, // 是否自動播放
          muted: false, // 是否靜音
          controls: false,
          fluid: true, // 寬高自適應
          sources: [{
            src: 'rtmp://-----------------------',
            type: 'rtmp/flv'
          }]
        }
mounted()中

this.player1 = videojs('my-player1', this.options1, function onPlayerReady() {
        videojs.log('播放器已經准備好了!')
        this.on('play', function() {
          console.log('開始/恢復播放')
        })
        this.on('pause', function() {
          console.log('暫停播放')
        })
        this.on('ended', function() {
          console.log('結束播放')
        })
      })
      this.player1.play()

 



切換視頻源,踩了坑記錄下,就下面幾行代碼:
this.player1 = videojs('my-player1', this.options1, function onPlayerReady() {
            var player1 = this
            player1.src({ src: 'rtmp://------------------', type: 'rtmp/flv' })
            this.play()
          })

 


免責聲明!

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



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