//此处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
}