diff --git a/assets/video/Website_version_opt.mp4 b/assets/video/Website_version_opt.mp4 new file mode 100644 index 0000000..cd47f4b Binary files /dev/null and b/assets/video/Website_version_opt.mp4 differ diff --git a/assets/video/mobile_version_opt.mp4 b/assets/video/mobile_version_opt.mp4 new file mode 100644 index 0000000..e7c0e67 Binary files /dev/null and b/assets/video/mobile_version_opt.mp4 differ diff --git a/site/blueprints/pages/home.yml b/site/blueprints/pages/home.yml index 04c61f3..2e4a020 100644 --- a/site/blueprints/pages/home.yml +++ b/site/blueprints/pages/home.yml @@ -41,7 +41,7 @@ tabs: type: fields fields: backgroundVideo: - label: Vidéo d'arrière-plan + label: Vidéo d'arrière-plan (desktop) type: files layout: cards max: 1 @@ -52,3 +52,35 @@ tabs: cover: true uploads: template: video + backgroundVideoPoster: + label: Poster vidéo desktop (affiché pendant le chargement) + type: files + layout: cards + max: 1 + accept: image/* + translate: false + image: + ratio: 16/9 + cover: true + backgroundVideoMobile: + label: Vidéo d'arrière-plan (mobile) + type: files + layout: cards + max: 1 + accept: video/* + translate: false + image: + ratio: 9/16 + cover: true + uploads: + template: video + backgroundVideoMobilePoster: + label: Poster vidéo mobile (affiché pendant le chargement) + type: files + layout: cards + max: 1 + accept: image/* + translate: false + image: + ratio: 9/16 + cover: true diff --git a/site/templates/home.json.php b/site/templates/home.json.php index 3f6f227..a7d53c2 100644 --- a/site/templates/home.json.php +++ b/site/templates/home.json.php @@ -9,7 +9,10 @@ $specificData = [ 'ctaPath' => $page->ctaLink()->toPage()?->id() ?? '#', 'image' => $page->heroImage()->toFile()?->url() ], - 'backgroundVideo' => $page->backgroundVideo()->toFile()?->url(), + 'backgroundVideo' => $page->backgroundVideo()->toFile()?->url(), + 'backgroundVideoPoster' => $page->backgroundVideoPoster()->toFile()?->url(), + 'backgroundVideoMobile' => $page->backgroundVideoMobile()->toFile()?->url(), + 'backgroundVideoMobilePoster' => $page->backgroundVideoMobilePoster()->toFile()?->url(), 'floatingBubbles' => $page->floatingBubbles()->toStructure()->map(function($bubble) { return [ 'text' => $bubble->text()->value(), diff --git a/src/views/Home.svelte b/src/views/Home.svelte index 602ac02..866422f 100644 --- a/src/views/Home.svelte +++ b/src/views/Home.svelte @@ -7,36 +7,34 @@ const currentLang = $derived(locale.current) - onMount(() => { - const playVideo = async (videoId) => { - const video = document.getElementById(videoId) - if (video) { - try { - video.muted = true - video.playsInline = true - const playPromise = video.play() - if (playPromise !== undefined) { - await playPromise - } - } catch (error) { - console.log(`Autoplay failed for ${videoId}:`, error) - const playOnInteraction = () => { - video.play().catch(e => console.log('Fallback play failed:', e)) - document.removeEventListener('click', playOnInteraction) - document.removeEventListener('touchstart', playOnInteraction) - } - document.addEventListener('click', playOnInteraction) - document.addEventListener('touchstart', playOnInteraction) + function playWhenReady(video) { + if (!video) return + + const attempt = () => { + video.muted = true + video.playsInline = true + video.play().catch(() => { + // Autoplay bloqué : on attend une interaction + const onInteraction = () => { + video.play().catch(() => {}) + document.removeEventListener('click', onInteraction) + document.removeEventListener('touchstart', onInteraction) } - } + document.addEventListener('click', onInteraction) + document.addEventListener('touchstart', onInteraction) + }) } - const timer = setTimeout(() => { - playVideo('home-video') - playVideo('home-video-mobile') - }, 100) + if (video.readyState >= 3) { + attempt() + } else { + video.addEventListener('canplay', attempt, { once: true }) + } + } - return () => clearTimeout(timer) + onMount(() => { + playWhenReady(document.getElementById('home-video')) + playWhenReady(document.getElementById('home-video-mobile')) }) function handleExplore() { @@ -49,27 +47,25 @@