import ReactPlayer, { ReactPlayerProps } from 'react-player/lazy' import React, { useState } from 'react' import BackgroundImageContainer from './BackgroundImage' import videoUrlHelper from '../../utils/videoUrlHelper' import { LmSectionVideoProps } from './sectionTypes' import clsx from 'clsx' type ContainerDimensions = { width: number height: number } type FullscreenVideoBgProps = LmSectionVideoProps['content'] & { containerDimensions: ContainerDimensions fixedToRatio: boolean ratioHeight: number ratioWidth: number inView: boolean } export default function FullscreenVideoBg( content: FullscreenVideoBgProps ): JSX.Element { const { inView, property, ratioHeight, ratioWidth } = content const properties = property || [] const videoAspect = ratioHeight / ratioWidth // let fixedToRatio = content.fixedToRatio const [error, setError] = useState() const className = clsx('react-player') const videoUrl = content.url_internal?.filename || content.url || '' if (!videoUrl) { return
please insert a video URL
} const muted = properties.includes('muted') const playerProps: ReactPlayerProps = { loop: properties.includes('loop'), playing: properties.includes('autoplay'), muted, controls: properties.includes('controls'), playsinline: properties.includes('playsinline'), light: properties.includes('light') ? content.fallback_image || true : false, onError: (error) => setError(error), volume: muted ? 0 : undefined } // calculate video container to fit into available space const windowWidth = content.containerDimensions.width const windowHeight = content.containerDimensions.height const windowAspect = windowHeight / windowWidth let vidBgWidth = '100%' if (windowAspect > videoAspect) { vidBgWidth = `${((windowAspect / videoAspect) * 100).toFixed(2)}%` } if (error) { console.error(error) } return ( <>
{error && content.fallback_image && ( )} ) }