pluginsSlice, sync videos playback state

This commit is contained in:
VDawg 2023-11-14 11:57:07 +01:00
parent 7f98db23d5
commit 8874252596
2 changed files with 19 additions and 2 deletions

View File

@ -10,11 +10,13 @@
export let poster export let poster
export let loop = true export let loop = true
export let muted = true export let muted = true
export let autoplay = false /** @type {true | undefined}*/
export let autoplay = undefined
export let hidden = false export let hidden = false
/** @type {string}*/ /** @type {string}*/
export let videoClass = '' export let videoClass = ''
let videoElement /** @type {HTMLVideoElement}*/
export let videoElement
let isPaused = true let isPaused = true
function togglePlay() { function togglePlay() {
@ -47,6 +49,9 @@
{poster} {poster}
on:click={togglePlay} on:click={togglePlay}
on:dblclick={makeFullscreen} on:dblclick={makeFullscreen}
on:play
on:pause
on:pause={() => (isPaused = true)}
{autoplay} {autoplay}
on:play={() => (isPaused = false)} on:play={() => (isPaused = false)}
/> />

View File

@ -7,6 +7,8 @@
import Video from '$lib/components/Video.svelte' import Video from '$lib/components/Video.svelte'
import { fade } from 'svelte/transition' import { fade } from 'svelte/transition'
/** @type {HTMLVideoElement[]}*/
const videos = []
let activeIndex = 0 let activeIndex = 0
const items = [ const items = [
@ -30,6 +32,13 @@
function setActiveItem(index) { function setActiveItem(index) {
activeIndex = index activeIndex = index
} }
function playVideos() {
videos.forEach((video) => video.play())
}
function pauseVideos() {
videos.forEach((video) => video.pause())
}
</script> </script>
<section class="relative z-0 flex min-h-max w-full flex-col items-center py-20"> <section class="relative z-0 flex min-h-max w-full flex-col items-center py-20">
@ -92,8 +101,11 @@
{src} {src}
{poster} {poster}
autoplay autoplay
bind:videoElement={videos[index]}
class="z-10 aspect-video h-[inherit] origin-left rounded-lg object-cover object-left shadow-xl shadow-cyan-700/50 outline outline-2 outline-cyan-500 duration-500" class="z-10 aspect-video h-[inherit] origin-left rounded-lg object-cover object-left shadow-xl shadow-cyan-700/50 outline outline-2 outline-cyan-500 duration-500"
hidden={index !== activeIndex} hidden={index !== activeIndex}
on:pause={pauseVideos}
on:play={playVideos}
videoClass="h-[inherit] aspect-video" videoClass="h-[inherit] aspect-video"
/> />
{/each} {/each}