vue实现 .flv 视频流播放
一、安装 flv.js
npm install flv.js -S
二、引入项目
import flvjs from 'flv.js/dist/flv.js'
三、使用
var self;
export default {
	  data() {
	    return {
	      flvPlayer: null,
	    };
	  },
	  props: {
	    videoSrc: {
	      type: String
	    }
	  },
	 mounted() {
	    self = this;
	    this.initFlvjs();
	  },
	  methods: {
	    initFlvjs() {
	      if (flvjs.isSupported()) {
	        this.flvPlayer = flvjs.createPlayer({
	          type: 'flv',
	          url: self.videoSrc
	        })
	        this.flvPlayer.attachMediaElement(self.$refs.videoContain)
	        this.flvPlayer.load()
	        this.flvPlayer.play()
	      }
	    }
	  },
	  destroyed() {
	    if (this.flvPlayer) {
	      this.flvPlayer.destroy();
	    }
	  }
  }

注:关闭时候需要销毁视频流!

Logo

前往低代码交流专区

更多推荐