Skip to content

Commit fb404c3

Browse files
susnuxbackportbot[bot]
authored andcommitted
fix: handle disabled auto-play in other browsers than Firefox
* Resolves #1323 We already support firefox but other browsers also can disabled autoplay and do not properly implement the API. So we need to check it manually. Can be tested with Vivaldi. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de> [skip ci]
1 parent 510aa5c commit fb404c3

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SPDX-FileCopyrightText = "2024 Nextcloud GmbH and Nextcloud contributors"
3636
SPDX-License-Identifier = "AGPL-3.0-or-later"
3737

3838
[[annotations]]
39-
path = ["img/Nextcloud.mp4", "img/Nextcloud.webm", "img/Nextcloud.webp", "img/nextcloudLogo.svg"]
39+
path = ["img/Nextcloud.mp4", "img/Nextcloud.webm", "img/Nextcloud.webp", "img/Nextcloud-preload.webp", "img/nextcloudLogo.svg"]
4040
precedence = "aggregate"
4141
SPDX-FileCopyrightText = "2019 Nextcloud GmbH"
4242
SPDX-License-Identifier = "LicenseRef-NextcloudTrademarks"

img/Nextcloud-preload.webp

3.69 KB
Loading

src/components/pages/IntroAnimation.vue

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
playsinline
1212
autoplay
1313
muted
14-
@ended="handleEnded">
14+
:poster="videoPoster"
15+
@ended="handleEnded"
16+
@play="videoStarted = true">
1517
<source :src="videoWebm" type="video/webm">
1618
<source :src="videoMp4" type="video/mp4">
1719
{{ videoFallbackText }}
@@ -22,25 +24,39 @@
2224
<script setup lang="ts">
2325
import { translate as t } from '@nextcloud/l10n'
2426
import { imagePath } from '@nextcloud/router'
25-
import { onMounted, useTemplateRef } from 'vue'
27+
import { computed, onMounted, ref, useTemplateRef } from 'vue'
2628
2729
const emit = defineEmits<{
2830
(e: 'next'): void
2931
}>()
3032
3133
const videoMp4 = imagePath('firstrunwizard', 'Nextcloud.mp4')
3234
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
3437
const videoFallbackText = t('firstrunwizard', 'Welcome to {cloudName}!', { cloudName: window.OC.theme.name })
3538
3639
const videoElement = useTemplateRef('video')
3740
41+
const autoPlayDisabled = ref(false)
42+
const videoStarted = ref(false)
43+
const videoPoster = computed(() => (autoPlayDisabled.value || videoStarted.value) ? videoFallbackImage : videoFallbackImagePre)
44+
3845
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)
4460
})
4561
4662
/**

0 commit comments

Comments
 (0)