基于flv.js播放青柿流媒体并控制摄像头封装JS包(部分功能)

//此处startPlay调用传输值
//ID为青柿流媒体提供接口查询出的设备列表中单个的设备ID
//token是青柿鉴权令牌
//ele为调用页要渲染的video元素

将your URL替换为青柿请求地址及可使用

import flvjs from 'flv.js'
import Vue from 'vue'
let that = new Vue()
let myId, myToken, flvPlayer;
//直播流渲染至元素
let startPlay = (id, token, ele) => {
	console.log(1)
	myId = id;
	myToken = token;
	that.$axios.get(#YOUR URL#, {
		params: {
			token: token,
			serial: id
		}
	}).then(res => {
		if (flvjs.isSupported()) {
			let videoElement = ele;
			flvPlayer = flvjs.createPlayer({
				type: 'flv',
				isLive: true,
				hasAudio: false,
				url: res.data.FLV
			});
			flvPlayer.attachMediaElement(videoElement)
			flvPlayer.load();
			flvPlayer.play();
		}
	})
}
//摄像头操作请求
let cameraReq = (instruct, str) => {
	let myStr = str != undefined ? str : "ptz"
	that.$axios.get(#YOUR URL#, {
		params: {
			serial: myId,
			command: instruct,
			token: myToken
		}
	}).then(() => {})
}
//停止动作
let cameraReqStop = (str) => {
	let myStr = str != undefined ? str : 'ptz'
	that.$axios.get(#YOUR URL#, {
		params: {
			serial: myId,
			command: "stop",
			token: myToken
		}
	}).then(() => {})
}
//关闭直播流
let cameraClose = () => {
	that.$axios.get(#YOUR URL#, {
		params: {
			serial: myId,
			token: myToken
		}
	}).then(() => {})
}
//摄像头补光灯
let fillLight = (state) => {
	let myState = state?"on":"off"
	console.log(myState)
	that.$axios.get(#YOUR URL#, {
		params: {
			serial: myId,
			token: myToken,
			command:myState
		}
	}).then((res) => {
		console.log(res)
	})
}
export default {
	startPlay,
	cameraReq,
	cameraReqStop,
	cameraClose,
	fillLight
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值