createPlayer.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <template>
  2. <div id="LivePlayerBox">
  3. <component v-for="(item, index) in streamList" :key="index" :is="item.zj" :src="item.src" class="liveVideo" />
  4. </div>
  5. </template>
  6. <script setup lang="ts">
  7. import { ref, onMounted, h, onBeforeMount, onUnmounted, onBeforeUnmount } from 'vue';
  8. import HlsPlayer from '@/components/vent/camera/HlsPlayer.vue';
  9. import LivePlayerWrapper from '@/components/vent/camera/LivePlayerWrapper.vue';
  10. const props = defineProps<{
  11. srcList: any[];
  12. }>();
  13. const streamList = ref<any[]>([]);
  14. onMounted(() => {
  15. const componentList: any[] = [];
  16. for (let i = 0; i < props.srcList.length; i++) {
  17. const stream = props.srcList[i];
  18. if (stream.addr.includes('0.0.0.0')) {
  19. stream.addr = stream.addr.replace('0.0.0.0', window.location.hostname);
  20. }
  21. if (stream.addr.toLowerCase().includes('.m3u8') || stream.addr.toLowerCase().startsWith('rtsp://')) {
  22. componentList.push({ zj: HlsPlayer, src: stream.addr });
  23. } else if (stream.addr.startsWith('rtmp://')) {
  24. componentList.push({ zj: LivePlayerWrapper, src: stream.addr });
  25. } else {
  26. componentList.push({ zj: LivePlayerWrapper, src: stream.addr });
  27. }
  28. }
  29. streamList.value = componentList;
  30. });
  31. onBeforeUnmount(() => {
  32. streamList.value = [];
  33. });
  34. </script>