vue使用xgplayer教程(flv直播流、flv格式视频)

在这里插入图片描述
在这里插入图片描述

安装

# 最新稳定版
$ npm install xgplayer
$ npm install xgplayer-flv

使用

<!-- 直播DOM--->
<div id="flv_live"></div>
<!-- 视频DOM--->
<div id="flv_video"></div>
import Player from "xgplayer";
import FlvPlayer from "xgplayer-flv";
export default{
	data(){
		return{
		player:null,
		}
	},
	mounted(){
		this.startPlayLive();
	},
	methods:{
		startPlayLive(){
			this.player=new Player({
				id:"flv_live",
				url:"http:localhost:8080/live/livestream.flv",
				isLive:true,
				autoplay:true,
				autoplayMuted:true,//进入页面自动播放直播流要打开此属性,默认为静音状态。
				playbackRate: [],//不打开倍速
				height: window.innerHeight,
				width: window.innerWidth,
				plugins:["FlvPlayer"],
				cors:true,
				fixVideoSize:"auto",
				volume:1,
			});
			this.player.once("canplay",()=>{
				this.play.pause();
				this.play.destory();
				this.play=null;
				this.startPlayLive();
			});
			this.player.once("ended",()=>{
				this.play.pause();
				this.play.destory();
				this.play=null;
				this.startPlayLive();
			});
			this.player.once("error",()=>{
				this.play.pause();
				this.play.destory();
				this.play=null;
				this.startPlayLive();
			})
		}
	}
	startPlay(){
		this.player=new Player({
				id:"flv_live",
				url:"http:localhost:8080/live/livestream.flv",
				autoplay: true,
		//		playbackRate: [0.5, 0.75, 1, 1.5, 2], 默认倍速打开
				height: window.innerHeight,
				width: window.innerWidth,
				plugins:["FlvPlayer"],
				cors:true,
				fixVideoSize:"auto",
				volume:1,
			});
	} 
}

测试视频流

FLV:

超清 https://sf1-hscdn-tos.pstatp.com/obj/media-fe/xgplayer_doc_video/flv/xgplayer-demo-720p.flv
高清 https://sf1-hscdn-tos.pstatp.com/obj/media-fe/xgplayer_doc_video/flv/xgplayer-demo-480p.flv
标清 https://sf1-hscdn-tos.pstatp.com/obj/media-fe/xgplayer_doc_video/flv/xgplayer-demo-360p.flv

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值