Commit 7449c87ce1b318dd1f193aed039366da97e87d91
1 parent
6529af99
perf: usage video.js refactor camera manage preview video modal
Showing
1 changed file
with
24 additions
and
78 deletions
| ... | ... | @@ -3,117 +3,63 @@ |
| 3 | 3 | <BasicModal |
| 4 | 4 | v-bind="$attrs" |
| 5 | 5 | width="55rem" |
| 6 | + destroyOnClose | |
| 6 | 7 | :height="heightNum" |
| 7 | 8 | @register="register" |
| 8 | 9 | title="视频预览" |
| 9 | - @cancel="handleCancel" | |
| 10 | 10 | :showOkBtn="false" |
| 11 | + @cancel="handleCancel" | |
| 11 | 12 | > |
| 12 | - <div class="video-sty"> | |
| 13 | - <div> | |
| 14 | - <videoPlay | |
| 15 | - v-if="showVideo" | |
| 16 | - ref="video" | |
| 17 | - style="display: inline-block; width: 100%" | |
| 18 | - v-bind="options" | |
| 19 | - /> | |
| 20 | - </div> | |
| 13 | + <div class="flex items-center justify-center bg-dark-900 w-full h-full min-h-52"> | |
| 14 | + <BasicVideoPlay v-if="showVideo" :options="options" /> | |
| 21 | 15 | </div> |
| 22 | - <!-- <div | |
| 23 | - class="bg-black h-80 text-light-50 w-full h-full flex justify-center items-center" | |
| 24 | - v-if="!showVideo" | |
| 25 | - > | |
| 26 | - 视频播放出错啦! | |
| 27 | - </div> --> | |
| 28 | 16 | </BasicModal> |
| 29 | 17 | </div> |
| 30 | 18 | </template> |
| 31 | 19 | <script setup lang="ts"> |
| 32 | - import { ref, nextTick, reactive } from 'vue'; | |
| 20 | + import { ref, reactive } from 'vue'; | |
| 33 | 21 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
| 34 | 22 | import type { StreamingManageRecord, CameraModel } from '/@/api/camera/model/cameraModel'; |
| 35 | - import { videoPlay } from 'vue3-video-play'; // 引入组件 | |
| 36 | - import 'vue3-video-play/dist/style.css'; // 引入css | |
| 37 | - import { AccessMode, MediaType } from './config.data'; | |
| 23 | + import { BasicVideoPlay, getVideoTypeByUrl } from '/@/components/Video'; | |
| 24 | + import { AccessMode } from './config.data'; | |
| 38 | 25 | import { getStreamingPlayUrl } from '/@/api/camera/cameraManager'; |
| 26 | + import { VideoJsPlayerOptions } from 'video.js'; | |
| 39 | 27 | |
| 40 | 28 | const heightNum = ref(800); |
| 41 | 29 | const showVideo = ref(false); |
| 42 | - const options = reactive({ | |
| 43 | - width: '800px', | |
| 44 | - height: '450px', | |
| 45 | - color: '#409eff', | |
| 46 | - muted: false, //静音 | |
| 47 | - webFullScreen: false, | |
| 48 | - autoPlay: true, //自动播放 | |
| 49 | - currentTime: 0, | |
| 50 | - loop: false, //循环播放 | |
| 51 | - mirror: false, //镜像画面 | |
| 52 | - ligthOff: false, //关灯模式 | |
| 53 | - volume: 0.3, //默认音量大小 | |
| 54 | - control: true, //是否显示控制器 | |
| 55 | - title: '', //视频名称 | |
| 56 | - type: 'm3u8', | |
| 57 | - src: '', //视频源 | |
| 58 | - controlBtns: [ | |
| 59 | - 'audioTrack', | |
| 60 | - 'quality', | |
| 61 | - 'speedRate', | |
| 62 | - 'volume', | |
| 63 | - 'setting', | |
| 64 | - 'pip', | |
| 65 | - 'pageFullScreen', | |
| 66 | - 'fullScreen', | |
| 67 | - ], | |
| 30 | + const options = reactive<VideoJsPlayerOptions>({ | |
| 31 | + width: '100%' as unknown as number, | |
| 32 | + height: '100%' as unknown as number, | |
| 33 | + autoplay: true, | |
| 68 | 34 | }); |
| 69 | - const video: any = ref(null); | |
| 70 | 35 | |
| 71 | - nextTick(() => { | |
| 72 | - console.log(video.value); | |
| 73 | - }); | |
| 74 | - | |
| 75 | - const getMediaType = (suffix: string) => { | |
| 76 | - return suffix === MediaType.M3U8 ? suffix : `video/${suffix}`; | |
| 36 | + const setSources = (url: string) => { | |
| 37 | + options.sources = [ | |
| 38 | + { | |
| 39 | + src: url, | |
| 40 | + type: getVideoTypeByUrl(url), | |
| 41 | + }, | |
| 42 | + ]; | |
| 77 | 43 | }; |
| 78 | 44 | |
| 79 | 45 | const [register] = useModalInner( |
| 80 | 46 | async (data: { record: CameraModel | StreamingManageRecord }) => { |
| 81 | - let reg = /(?:.*)(?<=\.)/; | |
| 82 | 47 | const { record } = data; |
| 83 | 48 | if (record.accessMode === AccessMode.ManuallyEnter) { |
| 84 | 49 | if ((record as CameraModel).videoUrl) { |
| 85 | - const type = (record as CameraModel).videoUrl.replace(reg, ''); | |
| 86 | - showVideo.value = true; | |
| 87 | - options.type = getMediaType(type); | |
| 88 | - options.src = (record as CameraModel).videoUrl; | |
| 89 | - options.autoPlay = true; | |
| 50 | + setSources((record as CameraModel).videoUrl); | |
| 90 | 51 | } |
| 91 | 52 | } else { |
| 92 | 53 | try { |
| 93 | 54 | const { data: { url } = { url: '' } } = await getStreamingPlayUrl(record.id!); |
| 94 | - showVideo.value = true; | |
| 95 | - options.src = url; | |
| 96 | - const type = (url as CameraModel).videoUrl.replace(reg, ''); | |
| 97 | - options.type = getMediaType(type); | |
| 98 | - } catch (error) { | |
| 99 | - } finally { | |
| 100 | - showVideo.value = true; | |
| 101 | - } | |
| 55 | + setSources(url); | |
| 56 | + } catch (error) {} | |
| 102 | 57 | } |
| 58 | + showVideo.value = true; | |
| 103 | 59 | } |
| 104 | 60 | ); |
| 105 | 61 | |
| 106 | 62 | const handleCancel = () => { |
| 107 | - //关闭暂停播放视频 | |
| 108 | - options.src = ''; | |
| 109 | - video.value.pause(); | |
| 63 | + showVideo.value = false; | |
| 110 | 64 | }; |
| 111 | 65 | </script> |
| 112 | -<style> | |
| 113 | - .video-sty { | |
| 114 | - width: 100%; | |
| 115 | - display: flex; | |
| 116 | - align-items: center; | |
| 117 | - justify-content: center; | |
| 118 | - } | |
| 119 | -</style> | ... | ... |