This commit is contained in:
duanxiaohai 2024-08-26 09:09:15 +08:00
parent 876e15a98d
commit d71cad9ef2
5 changed files with 182 additions and 67 deletions

BIN
dist.zip

Binary file not shown.

View File

@ -39,7 +39,7 @@
</div>
</div>
<div
id="videoBox"
id="videoBox2"
style="
width: 100%;
height: calc(100% - 110px);
@ -49,7 +49,7 @@
"
>
<video
id="videoPlayer"
id="videoPlayerInside"
class="video-js vjs-default-skin"
controls
playsinline
@ -70,15 +70,11 @@ import { CircleCloseFilled } from "@element-plus/icons-vue";
const props = defineProps({
cameraShow: {
type: Boolean,
default: () => {
return false;
},
default: false,
},
hlsUriSsl: {
type: String,
default: () => {
return "";
},
default: "",
},
});
const emit = defineEmits(["close"]);
@ -87,57 +83,15 @@ const emit = defineEmits(["close"]);
const cameraShow = ref();
const data = reactive({
title: "摄像头",
columns: [],
tableData: [],
// columns: [],
// tableData: [],
});
// const gridData = [];
const num = ref(false);
const hlsUriSslNow = ref("");
const gridData = [];
//
watch(
() => props.cameraShow,
(newVal, oldVal) => {
if (newVal) {
if (hlsUriSslNow.value == "") {
num.value = false;
} else {
num.value = true;
}
// if (hlsUriSslNow.value != "" && props.hlsUriSsl != hlsUriSslNow.value)
cameraShow.value = newVal;
hlsUriSslNow.value = props.hlsUriSsl;
attachmentLink.value = hlsUriSslNow.value;
dp.value = null;
//dom
if (num.value) {
console.log(22222, document.getElementById("videoBox"));
insertVideo();
}
nextTick(() => {
setTimeout(() => {
loadVideo();
}, 1000);
});
}
}
);
const insertVideo = () => {
const videoElement = document.createElement("video");
videoElement.id = "videoPlayer";
videoElement.className = "video-js vjs-default-skin";
videoElement.controls = true;
videoElement.crossOrigin = "anonymous";
videoElement.playsinline = true;
videoElement.autoplay = true;
const sourceElement = document.createElement("source");
sourceElement.src = attachmentLink.value;
sourceElement.type = "application/x-mpegURL";
videoElement.appendChild(sourceElement);
document.getElementById("videoBox").appendChild(videoElement);
};
const dp = ref(null);
const videohtml = ref("");
const attachmentLink = ref("");
const options = {
playbackRates: [1.0],
aspectRatio: "10:5",
@ -147,11 +101,176 @@ const options = {
preload: "auto",
controls: true,
};
// cameraShow
// watch(
// () => props.cameraShow,
// (newVal) => {
// if (newVal) {
// if (hlsUriSslNow.value == "") {
// num.value = false;
// } else {
// num.value = true;
// }
// // if (hlsUriSslNow.value != "" && props.hlsUriSsl != hlsUriSslNow.value)
// cameraShow.value = newVal;
// hlsUriSslNow.value = props.hlsUriSsl;
// attachmentLink.value = hlsUriSslNow.value;
// dp.value = null;
// //dom
// if (num.value) {
// // console.log(22222, document.getElementById("videoBox"));
// console.log("VideoBox element before insertion:", document.getElementById("videoBox"));
// insertVideo();
// }
// nextTick(() => {
// setTimeout(() => {
// loadVideo();
// }, 1500);
// });
// }
// }
// );
watch(
() => props.cameraShow,
(newVal) => {
if (newVal) {
//
initializeVideo();
} else {
//
disposeVideo();
}
}
);
const initializeVideo = () => {
if (hlsUriSslNow.value === "") {
num.value = false;
} else {
num.value = true;
}
cameraShow.value = props.cameraShow;
hlsUriSslNow.value = props.hlsUriSsl;
attachmentLink.value = hlsUriSslNow.value;
if (num.value) {
console.log("插入前的VideoBox元素", document.getElementById("videoBox"));
insertVideo();
}
nextTick(() => {
setTimeout(() => {
loadVideo();
}, 1500);
});
};
const insertVideo = () => {
const videoBox = document.getElementById("videoBox2");
if (!videoBox) {
console.error("找不到videoBox元素。确保元素存在于DOM中。");
return;
}
//
videoBox.innerHTML = "";
const videoElement = document.createElement("video");
videoElement.id = "videoPlayerInside";
videoElement.className = "video-js vjs-default-skin";
videoElement.controls = true;
videoElement.crossOrigin = "anonymous";
videoElement.playsinline = true;
videoElement.autoplay = true;
const sourceElement = document.createElement("source");
sourceElement.src = attachmentLink.value;
sourceElement.type = "application/x-mpegURL";
videoElement.appendChild(sourceElement);
videoBox.appendChild(videoElement);
console.log("插入视频元素:", videoElement);
};
// const insertVideo = () => {
// const videoElement = document.createElement("video");
// videoElement.id = "videoPlayer";
// videoElement.className = "video-js vjs-default-skin";
// videoElement.controls = true;
// videoElement.crossOrigin = "anonymous";
// videoElement.playsinline = true;
// videoElement.autoplay = true;
// const sourceElement = document.createElement("source");
// sourceElement.src = attachmentLink.value;
// sourceElement.type = "application/x-mpegURL";
// videoElement.appendChild(sourceElement);
// document.getElementById("videoBox").appendChild(videoElement);
// };
// const insertVideo = () => {
// const videoBox = document.getElementById("videoBox");
// if (!videoBox) {
// console.error("videoBox element not found. Ensure the element exists in the DOM.");
// return;
// }
// // Clear any existing video element inside videoBox
// videoBox.innerHTML = "";
// const videoElement = document.createElement("video");
// videoElement.id = "videoPlayer";
// videoElement.className = "video-js vjs-default-skin";
// videoElement.controls = true;
// videoElement.crossOrigin = "anonymous";
// videoElement.playsinline = true;
// videoElement.autoplay = true;
// const sourceElement = document.createElement("source");
// sourceElement.src = attachmentLink.value;
// sourceElement.type = "application/x-mpegURL";
// videoElement.appendChild(sourceElement);
// videoBox.appendChild(videoElement);
// console.log(":", videoElement);
// };
// const dp = ref(null);
// const videohtml = ref("");
// const attachmentLink = ref("");
// const options = {
// playbackRates: [1.0],
// aspectRatio: "10:5",
// notSupportedMessage: "",
// autoplay: false,
// muted: true,
// preload: "auto",
// controls: true,
// };
const loadVideo = () => {
if (videoPlayer) {
dp.value = videojs("videoPlayer", options);
// if (videoPlayer) {
// dp.value = videojs("videoPlayer", options);
// }
if (dp.value) {
console.log("正在销毁之前的video.js实例。");
dp.value.dispose();
}
dp.value = videojs("videoPlayerInside", options);
console.log("Video.js播放器已加载", dp.value);
};
const disposeVideo = () => {
if (dp.value) {
dp.value.dispose(); // dispose()Dom
dp.value = null;
console.log("Video.js播放器已处理。");
}
// videoBox
// const videoBox = document.getElementById("videoBox");
// if (videoBox) {
// videoBox.innerHTML = "";
// console.log("videoBox");
// }
};
// 使
onMounted(() => {
@ -159,11 +278,7 @@ onMounted(() => {
});
const closeDialog = () => {
cameraShow.value = false;
if (dp.value) {
dp.value.dispose(); // dispose()Dom
// dp.value.pause();
dp.value = null;
}
disposeVideo();
emit("close");
};
</script>

View File

@ -54,7 +54,6 @@
controls
playsinline
autoplay="autoplay"
style="width: 100%; height: auto;"
>
<source :src="attachmentLink" type="application/x-mpegURL" />
</video>
@ -111,13 +110,12 @@ watch(
num.value = true;
}
// if (hlsUriSslNow.value != "" && props.hlsUriSsl != hlsUriSslNow.value)
data.title = props.sxtname;
cameraShow.value = newVal;
hlsUriSslNow.value = props.hlsUriSsl;
data.title = props.sxtname;
console.log(hlsUriSslNow.value, props.sxtname, 5555);
attachmentLink.value = hlsUriSslNow.value;
dp.value = null;
// console.log(hlsUriSslNow.value, props.sxtname, 5555);
//dom
if (num.value) {
console.log(22222, document.getElementById("videoBox"));
@ -178,6 +176,8 @@ const closeDialog = () => {
};
</script>
<style lang="scss" scoped>
//
::v-deep .video-js .vjs-big-play-button {

View File

@ -902,7 +902,7 @@ watch(
}
);
onMounted(() => {
// tools.data.set("token", "6b0e380b4a8f46baae4923f83faf670d");
tools.data.set("token", "6b0e380b4a8f46baae4923f83faf670d");
if (routers.query.type) {
errorMessage.value = "";
dataMyTag.identNo = routers.query.identNo;

View File

@ -3423,7 +3423,7 @@ const reset_font2 = () => {
"scale(" + width / 1920 + "," + height / 1080 + ")";
};
onMounted(async () => {
// tools.data.set("token", "6b0e380b4a8f46baae4923f83faf670d");
tools.data.set("token", "6b0e380b4a8f46baae4923f83faf670d");
loadingss.value = true;
reset_font();
initMap();