vue播放视频

vue播放视频

  • 安装依赖
npm install video.js
npm install aes-decrypter
npm install m3u8-parser
npm install mpd-parser
npm install mux.js
npm install url-toolkit
npm install videojs-contrib-hls
  • 前端跨域
proxyTable: {
    '/api': {  //使用"/api"来代替"http://f.apiplus.c" 
		target: 'http://127.0.0.1:8000/', //源地址 
		changeOrigin: true, //改变源 
		pathRewrite: { 
			'^/api': '' //路径重写 
		} 
	} 
},
  • 常用代码块
<template>
  <div id='play'>
	  <video id="my-video" class="video-js vjs-default-skin" controls preload="auto" >
		  <source :src="src" >
	  </video>
  </div>
</template>
<script>
import videojs from 'video.js'
import 'videojs-contrib-hls'
export default {
  name:'play',
  data(){
	  return {
		  src:''
	  }
  },
  created(){
	  // 应该去后台获取播放地址,实际上模拟地址了
	  this.src = '/api/static/video/list.m3u8';
  },
  mounted(){
	  videojs('my-video', {
		  bigPlayButton: true,
		  textTrackDisplay: false,
		  posterImage: true,
		  errorDisplay: false,
		  controlBar: true
	  }, function () {
		  this.play()
	  })
  }
}
</script>
posted @ 2019-10-29 07:55  巫小诗  阅读(1938)  评论(0编辑  收藏  举报