| | |
| | | <template> |
| | | <div class="centermap"> |
| | | <div class="mapwrap"> |
| | | <dv-border-box-13> |
| | | <video |
| | | ref="videoPlayer" |
| | | class="screen-video" |
| | | src="../../assets/img/2.mp4" |
| | | loop |
| | | autoplay |
| | | preload="auto" |
| | | muted |
| | | @click="unmuteVideo" |
| | | > |
| | | æ¨çæµè§å¨ä¸æ¯æè§é¢ææ¾ã |
| | | </video> |
| | | <div v-if="isMuted" class="mute-hint" @click="unmuteVideo"> |
| | | <span>ç¹å»åæ¶éé³ï¼5ç§åèªå¨ææ¾å£°é³ï¼</span> |
| | | </div> |
| | | </dv-border-box-13> |
| | | <ItemWrap title="è§é¢çæ§"> |
| | | <video id="video_left" autoplay muted controls playsinline width="100%" height="100%"></video> |
| | | </ItemWrap> |
| | | </div> |
| | | <div class="mapwrap"> |
| | | <ItemWrap title="è§é¢çæ§"> |
| | | <video id="video_right" autoplay muted controls playsinline width="100%" height="100%"></video> |
| | | </ItemWrap> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | data() { |
| | | return { |
| | | isMuted: false, |
| | | unmuteTimeout: null // åå¨å®æ¶å¨ä»¥ä¾¿æ¸
ç |
| | | }; |
| | | }, |
| | | mounted() { |
| | | this.initVideo(); |
| | | this.adjustVideoSize(); |
| | | window.addEventListener('resize', this.adjustVideoSize); |
| | | <script setup> |
| | | import { ref, onMounted, onUnmounted, onActivated, onDeactivated } from 'vue' |
| | | |
| | | // 5ç§åèªå¨åæ¶éé³ |
| | | this.unmuteTimeout = setTimeout(() => { |
| | | this.unmuteVideo(); |
| | | }, 5000); |
| | | }, |
| | | beforeDestroy() { |
| | | window.removeEventListener('resize', this.adjustVideoSize); |
| | | if (this.unmuteTimeout) { |
| | | clearTimeout(this.unmuteTimeout); // æ¸
é¤å®æ¶å¨é¿å
å
åæ³æ¼ |
| | | } |
| | | }, |
| | | methods: { |
| | | initVideo() { |
| | | const video = this.$refs.videoPlayer; |
| | | if (video) { |
| | | video.addEventListener('ended', () => { |
| | | video.currentTime = 0; |
| | | video.play(); |
| | | }); |
| | | } |
| | | document.addEventListener('click', this.unmuteVideo, { once: true }); |
| | | }, |
| | | unmuteVideo() { |
| | | const video = this.$refs.videoPlayer; |
| | | if (video) { |
| | | video.muted = false; |
| | | video.volume = 1.0; |
| | | this.isMuted = false; |
| | | } |
| | | }, |
| | | adjustVideoSize() { |
| | | const video = this.$refs.videoPlayer; |
| | | if (video) { |
| | | video.style.width = '100%'; |
| | | video.style.height = '100%'; |
| | | video.style.objectFit = 'cover'; |
| | | } |
| | | } |
| | | // WebRTC ææ¾å¨å®ä¾ |
| | | const webRtcServer_left = ref(null) |
| | | const webRtcServer_right = ref(null) |
| | | |
| | | // RTSP å°åï¼æ³¨æ URL ç¼ç ç¹æ®å符 |
| | | const rtspLeft = 'rtsp://admin:Mx202513@172.21.7.244:554/Streaming/Channels/102?rtsp_transport=tcp' |
| | | const rtspRight = 'rtsp://admin:Mx202513@172.21.7.244:554/Streaming/Channels/202?rtsp_transport=tcp' |
| | | |
| | | // WebRtcStreamer æå¡å°å |
| | | const serverUrl = 'http://172.21.1.139:8000' // â æ¹ä¸ºä½ è¿è¡ webrtcstreamer ççµè IP |
| | | |
| | | // åå§åè§é¢ææ¾ |
| | | const initVideo = () => { |
| | | try { |
| | | // å·¦æå头 |
| | | webRtcServer_left.value = new WebRtcStreamer('video_left', serverUrl) |
| | | webRtcServer_left.value.connect(rtspLeft) |
| | | |
| | | // 峿å头 |
| | | webRtcServer_right.value = new WebRtcStreamer('video_right', serverUrl) |
| | | webRtcServer_right.value.connect(rtspRight) |
| | | |
| | | console.log('è§é¢åå§å宿') |
| | | } catch (err) { |
| | | console.error('è§é¢åå§å失败: ' + err.message) |
| | | } |
| | | }; |
| | | } |
| | | |
| | | // 鿝è§é¢ææ¾ |
| | | const destroyVideo = () => { |
| | | if (webRtcServer_left.value) { |
| | | webRtcServer_left.value.disconnect() |
| | | webRtcServer_left.value = null |
| | | } |
| | | if (webRtcServer_right.value) { |
| | | webRtcServer_right.value.disconnect() |
| | | webRtcServer_right.value = null |
| | | } |
| | | } |
| | | |
| | | // 页颿¿æ´»æ¶ææ¾ |
| | | onActivated(() => { |
| | | ['video_left', 'video_right'].forEach(id => { |
| | | const video = document.getElementById(id) |
| | | if (video && video.paused) video.play() |
| | | }) |
| | | }) |
| | | |
| | | // 页é¢åç¨æ¶æå |
| | | onDeactivated(() => { |
| | | ['video_left', 'video_right'].forEach(id => { |
| | | const video = document.getElementById(id) |
| | | if (video && !video.paused) video.pause() |
| | | }) |
| | | }) |
| | | |
| | | // é¡µé¢æè½½åå§å |
| | | onMounted(() => { |
| | | initVideo() |
| | | }) |
| | | |
| | | // 页é¢å¸è½½éæ¯ |
| | | onUnmounted(() => { |
| | | destroyVideo() |
| | | }) |
| | | </script> |
| | | |
| | | <style scoped> |
| | | /* æ ·å¼ä¿æä¸å */ |
| | | .centermap { |
| | | width: 100%; |
| | | height: 100%; |
| | | |
| | | .mapwrap { |
| | | height: 960px; |
| | | width: 100%; |
| | | box-sizing: border-box; |
| | | position: relative; |
| | | margin-top: 10px; |
| | | |
| | | & > dv-border-box-13 { |
| | | width: 100%; |
| | | height: 100%; |
| | | position: relative; |
| | | overflow: hidden; |
| | | } |
| | | } |
| | | } |
| | | |
| | | .screen-video { |
| | | position: absolute; |
| | | top: 0; |
| | | left: 0; |
| | | .mapwrap { |
| | | height: 470px; |
| | | width: 100%; |
| | | height: 100%; |
| | | object-fit: cover; |
| | | box-sizing: border-box; |
| | | position: relative; |
| | | margin-top: 10px; |
| | | } |
| | | |
| | | .mute-hint { |
| | | position: absolute; |
| | | top: 50%; |
| | | left: 50%; |
| | | transform: translate(-50%, -50%); |
| | | background: rgba(0,0,0,0.7); |
| | | color: white; |
| | | padding: 10px 20px; |
| | | border-radius: 5px; |
| | | cursor: pointer; |
| | | z-index: 10; |
| | | } |
| | | </style> |
| | | </style> |