Commit 17e74d960994f0c293aa2a6d29be4977d13457bb

Authored by fengwotao
1 parent 29bde1de

fix(external/Componse): 修复摄像头更换源地址无法播放问题

@@ -4,7 +4,7 @@ import { CameraConfig } from './index' @@ -4,7 +4,7 @@ import { CameraConfig } from './index'
4 import cloneDeep from 'lodash/cloneDeep' 4 import cloneDeep from 'lodash/cloneDeep'
5 5
6 export const option = { 6 export const option = {
7 - dataset: 'http://113.204.115.250:83/openUrl/4itVrfG/live.m3u8' 7 + dataset: 'http://113.204.115.250:83/openUrl/zXuPw5y/live.m3u8'
8 } 8 }
9 9
10 export default class Config extends PublicConfigClass implements CreateComponentType { 10 export default class Config extends PublicConfigClass implements CreateComponentType {
1 <template> 1 <template>
2 <div class="go-content-box" :style="{ width: w + 'px', height: h + 'px' }"> 2 <div class="go-content-box" :style="{ width: w + 'px', height: h + 'px' }">
3 <video id="my-player" ref="videoRef" class="video-js my-video"> 3 <video id="my-player" ref="videoRef" class="video-js my-video">
4 - <source :src="props.chartConfig.option.dataset" /> 4 + <source :src="dataset" />
5 </video> 5 </video>
6 </div> 6 </div>
7 </template> 7 </template>
8 <script setup lang="ts"> 8 <script setup lang="ts">
9 -import { PropType, onMounted, ref, watch, toRefs } from 'vue' 9 +import { PropType, onMounted, ref, watch, toRefs, onUnmounted } from 'vue'
10 import { CreateComponentType } from '@/packages/index.d' 10 import { CreateComponentType } from '@/packages/index.d'
11 import videojs from 'video.js' 11 import videojs from 'video.js'
12 import type { VideoJsPlayerOptions } from 'video.js' 12 import type { VideoJsPlayerOptions } from 'video.js'
@@ -21,44 +21,49 @@ const props = defineProps({ @@ -21,44 +21,49 @@ const props = defineProps({
21 21
22 const { w, h } = toRefs(props.chartConfig.attr) 22 const { w, h } = toRefs(props.chartConfig.attr)
23 23
  24 +const { dataset } = toRefs(props.chartConfig.option)
  25 +
24 // video标签 26 // video标签
25 const videoRef = ref<HTMLElement | null>(null) 27 const videoRef = ref<HTMLElement | null>(null)
26 28
27 // video实例对象 29 // video实例对象
28 let videoPlayer: videojs.Player | null = null 30 let videoPlayer: videojs.Player | null = null
29 31
  32 +//options配置
  33 +const options: VideoJsPlayerOptions = {
  34 + language: 'zh-CN', // 设置语言
  35 + controls: true, // 是否显示控制条
  36 + preload: 'auto', // 预加载
  37 + autoplay: true, // 是否自动播放
  38 + fluid: false, // 自适应宽高
  39 + src: dataset?.value, // 要嵌入的视频源的源 URL
  40 + userActions: {
  41 + hotkeys: true
  42 + }
  43 +}
  44 +
30 // 初始化videojs 45 // 初始化videojs
31 const initVideo = () => { 46 const initVideo = () => {
32 - const options: VideoJsPlayerOptions = {  
33 - language: 'zh-CN', // 设置语言  
34 - controls: true, // 是否显示控制条  
35 - preload: 'auto', // 预加载  
36 - autoplay: true, // 是否自动播放  
37 - fluid: false, // 自适应宽高  
38 - src: props.chartConfig.option.dataset, // 要嵌入的视频源的源 URL  
39 - userActions: {  
40 - hotkeys: true  
41 - }  
42 - }  
43 if (videoRef.value) { 47 if (videoRef.value) {
44 // 创建 video 实例 48 // 创建 video 实例
45 - videoPlayer = videojs(videoRef.value, options, onPlayerReady) 49 + videoPlayer = videojs(videoRef.value, options)
46 } 50 }
47 } 51 }
48 52
49 -// video初始化完成的回调函数  
50 -const onPlayerReady = () => {}  
51 -  
52 onMounted(() => { 53 onMounted(() => {
53 initVideo() 54 initVideo()
54 }) 55 })
55 56
  57 +onUnmounted(() => {
  58 + videoPlayer?.dispose()
  59 +})
  60 +
56 watch( 61 watch(
57 () => props.chartConfig.option.dataset, 62 () => props.chartConfig.option.dataset,
58 newData => { 63 newData => {
59 - console.log(newData)  
60 props.chartConfig.option.dataset = newData 64 props.chartConfig.option.dataset = newData
61 - initVideo() 65 + videoPlayer?.src(newData)
  66 + videoPlayer?.play()
62 } 67 }
63 ) 68 )
64 </script> 69 </script>