Line data Source code
1 16 : <template>
2 2 : <video
3 : ref="video"
4 : controls
5 : :autoplay="autoplay"
6 : class="max-h-[90vh] max-w-[90vw]"
7 : >
8 : <source
9 : data-testid="result-video-source"
10 : :src="url"
11 : :type="htmlVideoType"
12 : />
13 : {{ $t('g.videoFailedToLoad') }}
14 : </video>
15 : </template>
16 :
17 : <script setup lang="ts">
18 : import { computed, onActivated, useTemplateRef } from 'vue'
19 :
20 : import { useSettingStore } from '@/platform/settings/settingStore'
21 : import { useExtensionStore } from '@/platform/extensions/stores/extensionStore'
22 : import type { AugmentedResultItem } from '@/utils/resultItem'
23 : import {
24 : resultItemUrl,
25 : resultItemVhsAdvancedPreviewUrl
26 : } from '@/utils/resultItemUrl'
27 : import { resultItemHtmlVideoType } from '@/utils/resultItem'
28 :
29 : /* MediaLightbox retains this component via KeepAlive include, which matches on
30 : the registered component name. */
31 : defineOptions({ name: 'ResultVideo' })
32 :
33 2 : const props = defineProps<{
34 : result: AugmentedResultItem
35 : autoplay?: boolean
36 : }>()
37 :
38 2 : const videoElement = useTemplateRef<HTMLVideoElement>('video')
39 :
40 2 : onActivated(() => {
41 2 : if (props.autoplay) void videoElement.value?.play().catch(() => {})
42 : })
43 :
44 2 : const settingStore = useSettingStore()
45 2 : const { isExtensionInstalled, isExtensionEnabled } = useExtensionStore()
46 :
47 2 : const playsResolvedUrl = computed(
48 : () => !!props.result.url && props.result.filenameIsDisplayName === true
49 : )
50 :
51 2 : const vhsAdvancedPreviews = computed(() => {
52 2 : return (
53 : !playsResolvedUrl.value &&
54 : isExtensionInstalled('VideoHelperSuite.Core') &&
55 : isExtensionEnabled('VideoHelperSuite.Core') &&
56 : settingStore.get('VHS.AdvancedPreviews') &&
57 : settingStore.get('VHS.AdvancedPreviews') !== 'Never'
58 : )
59 : })
60 :
61 2 : const url = computed(() =>
62 : vhsAdvancedPreviews.value
63 : ? resultItemVhsAdvancedPreviewUrl(props.result)
64 : : resultItemUrl(props.result)
65 : )
66 2 : const htmlVideoType = computed(() =>
67 : vhsAdvancedPreviews.value
68 : ? 'video/webm'
69 : : resultItemHtmlVideoType(props.result)
70 : )
71 : </script>
|