|
11 | 11 | playsinline |
12 | 12 | autoplay |
13 | 13 | muted |
14 | | - @ended="handleEnded"> |
| 14 | + :poster="videoPoster" |
| 15 | + @ended="handleEnded" |
| 16 | + @play="videoStarted = true"> |
15 | 17 | <source :src="videoWebm" type="video/webm"> |
16 | 18 | <source :src="videoMp4" type="video/mp4"> |
17 | 19 | {{ videoFallbackText }} |
|
22 | 24 | <script setup lang="ts"> |
23 | 25 | import { translate as t } from '@nextcloud/l10n' |
24 | 26 | import { imagePath } from '@nextcloud/router' |
25 | | -import { onMounted, useTemplateRef } from 'vue' |
| 27 | +import { computed, onMounted, ref, useTemplateRef } from 'vue' |
26 | 28 |
|
27 | 29 | const emit = defineEmits<{ |
28 | 30 | (e: 'next'): void |
29 | 31 | }>() |
30 | 32 |
|
31 | 33 | const videoMp4 = imagePath('firstrunwizard', 'Nextcloud.mp4') |
32 | 34 | const videoWebm = imagePath('firstrunwizard', 'Nextcloud.webm') |
33 | | -const videoFallbackImage = imagePath('firstrunwizard', 'Nextcloud.webp') |
| 35 | +const videoFallbackImagePre = imagePath('firstrunwizard', 'Nextcloud-preload.webp') // first frame of the video |
| 36 | +const videoFallbackImage = imagePath('firstrunwizard', 'Nextcloud.webp') // best visual fallback image of the video |
34 | 37 | const videoFallbackText = t('firstrunwizard', 'Welcome to {cloudName}!', { cloudName: window.OC.theme.name }) |
35 | 38 |
|
36 | 39 | const videoElement = useTemplateRef('video') |
37 | 40 |
|
| 41 | +const autoPlayDisabled = ref(false) |
| 42 | +const videoStarted = ref(false) |
| 43 | +const videoPoster = computed(() => (autoPlayDisabled.value || videoStarted.value) ? videoFallbackImage : videoFallbackImagePre) |
| 44 | +
|
38 | 45 | onMounted(() => { |
39 | | - // check if the browser allows auto play - otherwise we need to skip this |
40 | | - if (navigator.getAutoplayPolicy && navigator.getAutoplayPolicy(videoElement.value) === 'disallowed') { |
41 | | - videoElement.value!.poster = videoFallbackImage |
42 | | - window.setTimeout(handleEnded, 2500) |
43 | | - } |
| 46 | + autoPlayDisabled.value = 'getAutoplayPolicy' in navigator |
| 47 | + // @ts-expect-error -- firefox experimental API |
| 48 | + && navigator.getAutoplayPolicy(videoElement.value) === 'disallowed' |
| 49 | +
|
| 50 | + window.setTimeout(() => { |
| 51 | + if (!videoStarted.value || autoPlayDisabled) { |
| 52 | + // skip to the end after showing the fallback image for a short time |
| 53 | + window.setTimeout(handleEnded, 1700) |
| 54 | + } |
| 55 | + if (!videoStarted.value) { |
| 56 | + // video has not started playing within 800ms - probably due to browser restrictions |
| 57 | + videoStarted.value = true |
| 58 | + } |
| 59 | + }, 800) |
44 | 60 | }) |
45 | 61 |
|
46 | 62 | /** |
|
0 commit comments