π₯ Make videos programmatically with React
Player behavior and layout adjustment
MehmetAdemidf53b42e2240
diff --git a/packages/docs/components/LandingPage/VideoAppsShowcase.module.css b/packages/docs/components/LandingPage/VideoAppsShowcase.module.cssindex 97e438e156..2961d9fbe6 100644--- a/packages/docs/components/LandingPage/VideoAppsShowcase.module.css+++ b/packages/docs/components/LandingPage/VideoAppsShowcase.module.css@@ -63,19 +63,18 @@max-width: 500px; /* Adjust this value as needed */aspect-ratio: 1 / 1;position: relative;- border-radius: 8px; /* Add rounded corners to the video container */- overflow: hidden; /* Ensure video doesn't overflow rounded corners */+ border-radius: 8px;+ overflow: hidden;background-color: rgba(104, 104, 104, 0.171);}.video {position: absolute;- top: 50%;- left: 50%;- transform: translate(-50%, -50%);-+ top: 0;+ left: 0;+ width: 100%;height: 100%;-+ object-fit: contain;border-radius: 8px;}@@ -157,3 +156,25 @@.highlight {color: #007bff; /* or any color you prefer for "video apps" */}++.muteButton {+ position: absolute;+ bottom: 10px;+ right: 10px;+ background: rgba(0, 0, 0, 0.5);+ color: white;+ border: none;+ border-radius: 50%;+ width: 30px;+ height: 30px;+ display: flex;+ justify-content: center;+ align-items: center;+ font-size: 16px;+ cursor: pointer;+ transition: background-color 0.1s ease;+}++.muteButton:hover {+ background: rgba(0, 0, 0, 0.7);+}diff --git a/packages/docs/components/LandingPage/VideoAppsShowcase.tsx b/packages/docs/components/LandingPage/VideoAppsShowcase.tsxindex dde8f06935..b60b175629 100644--- a/packages/docs/components/LandingPage/VideoAppsShowcase.tsx+++ b/packages/docs/components/LandingPage/VideoAppsShowcase.tsx@@ -5,19 +5,29 @@ import {BlueButton} from '../layout/Button';import styles from './VideoAppsShowcase.module.css';const tabs = [+ 'Music visualization','Captions','Screencast',- 'Music visualization','Year in review',];const videoApps = [+ {+ title: 'Banger.Show',+ description:+ 'The all-in-one 3D visual creation tool for ambitious artists. Seamlessly craft visuals that match your sound and propel your brand forward.',+ link: 'https://banger.show?ref=remotion',+ videoWidth: 1080,+ videoHeight: 1080,+ muxId: 'riYdneJ2zu1Vqiayoe1qAZXcSIRq0201tHgSBbh9JbtlU',+ thumbnailSrc: '/img/homepage-showcase/banger-show-thumbnail.png',+ buttonText: 'Banger.Show website',+ },{title: 'Submagic',description:- 'A video editor for creating short-form content fast. Designed for creators, teams and agencies.',- additionalInfo:- 'Accelerates video editing with AI-powered features such as descriptions, zooms, sound effects and music.',+ 'A video editor for creating short-form content fast. Designed for creators, teams and agencies, it accelerates video editing with AI-powered features such as descriptions, zooms, sound effects and music.',+ additionalInfo: '',link: 'https://www.submagic.co/?ref=remotion',videoWidth: 540,videoHeight: 1080,@@ -29,7 +39,7 @@ const videoApps = [title: 'Remotion Recorder',description:'The Remotion Recorder is a video production tool built entirely in JavaScript. Create high-quality videos that feel native on each platform while only editing them once.',- additionalInfo: 'Various templates optimized for sharing on social media.',+link: 'https://www.remotion.pro/recorder',videoWidth: 1080,videoHeight: 1080,@@ -37,17 +47,6 @@ const videoApps = [thumbnailSrc: '/img/homepage-showcase/remotion-recorder-thumbnail.png',buttonText: 'More infos',},- {- title: 'Banger.Show',- description:- 'The all-in-one 3D visual creation tool for ambitious artists. Seamlessly craft visuals that match your sound and propel your brand forward.',- link: 'https://banger.show?ref=remotion',- videoWidth: 1080,- videoHeight: 1080,- muxId: 'riYdneJ2zu1Vqiayoe1qAZXcSIRq0201tHgSBbh9JbtlU',- thumbnailSrc: '/img/homepage-showcase/banger-show-thumbnail.png',- buttonText: 'Banger.Show website',- },{title: 'GitHub Unwrapped',description:@@ -63,25 +62,118 @@ const videoApps = [},];-const AUDIO_VOLUME = 0.05; // Adjust this value between 0 and 1 as needed+// const AUDIO_VOLUME = 0.05; // Adjust this value between 0 and 1 as neededconst VideoAppsShowcase: React.FC = () => {const [activeTab, setActiveTab] = useState(0);const [isPlaying, setIsPlaying] = useState(false);+ const [isMuted, setIsMuted] = useState(true);const videoRef = useRef<HTMLVideoElement>(null);+ const containerRef = useRef<HTMLDivElement>(null);++ useEffect(() => {+ setActiveTab(0); // Set to 0 for "Music visualization"++ const observer = new IntersectionObserver(+ (entries) => {+ if (entries[0].isIntersecting) {+ if (videoRef.current && videoRef.current.paused) {+ videoRef.current.muted = true; // Ensure video is muted before autoplay+ setIsMuted(true); // Update state to reflect muted status+ videoRef.current+ .play()+ .then(() => {+ setIsPlaying(true);+ })+ .catch((error) => {+ console.error('Playback error:', error);+ setIsPlaying(false);+ });+ }+ } else if (videoRef.current && !videoRef.current.paused) {+ videoRef.current.pause();+ setIsPlaying(false);+ }+ },+ {threshold: 0.5},+ );++ const currentContainer = containerRef.current;+ if (currentContainer) {+ observer.observe(currentContainer);+ }++ return () => {+ if (currentContainer) {+ observer.unobserve(currentContainer);+ }+ };+ }, []);useEffect(() => {- // Generate a random index when the component mounts- const randomIndex = Math.floor(Math.random() * tabs.length);- setActiveTab(randomIndex);- }, []); // Empty dependency array ensures this runs only once on mount+ setIsPlaying(false);+ const video = videoRef.current;+ if (video) {+ video.pause();+ video.currentTime = 0;+ video.load();++ // Check if the video is visible and play it if it is+ const observer = new IntersectionObserver(+ (entries) => {+ if (entries[0].isIntersecting) {+ // Introduce a delay before playing the video+ setTimeout(() => {+ if (video) {+ video.muted = true; // Ensure video is muted before autoplay+ setIsMuted(true); // Update state to reflect muted status+ video+ .play()+ .then(() => {+ setIsPlaying(true);+ })+ .catch((error) => {+ console.error('Playback error:', error);+ setIsPlaying(false);+ });+ }+ }, 750); // 750ms (0.75 second) delay, adjust as needed+ }+ },+ {threshold: 0.5},+ );++ observer.observe(video);++ return () => {+ observer.disconnect();+ video.muted = false; // Unmute the video when it's no longer visible+ if (video) {+ video.pause();+ video.currentTime = 0;+ video.load();+ }+ };+ }+ }, [activeTab]);const handlePlayPause = () => {if (videoRef.current) {if (videoRef.current.paused) {- videoRef.current.volume = AUDIO_VOLUME;- videoRef.current.play();- setIsPlaying(true);+ const playPromise = videoRef.current.play();++ if (playPromise !== undefined) {+ playPromise+ .then(() => {+ // Playback started successfully+ setIsPlaying(true);+ })+ .catch((error) => {+ // Auto-play was prevented or there was an error+ console.error('Playback error:', error);+ setIsPlaying(false);+ });+ }} else {videoRef.current.pause();setIsPlaying(false);@@ -89,13 +181,20 @@ const VideoAppsShowcase: React.FC = () => {}};+ const handleMuteToggle = () => {+ if (videoRef.current) {+ const newMutedState = !videoRef.current.muted;+ videoRef.current.muted = newMutedState;+ setIsMuted(newMutedState);+ }+ };+return (- <div className={styles.container}>+ <div ref={containerRef} className={styles.container}><div className={styles.titleContainer}><h2 className={styles.title}>- Create not just videos.- <br />- Create <span className={styles.highlight}>video apps.</span>+ Video apps created with{' '}+ <span className={styles.highlight}>Remotion</span></h2></div><div className={styles.tabs}>@@ -116,19 +215,27 @@ const VideoAppsShowcase: React.FC = () => {<MuxVideoref={videoRef}muxId={videoApps[activeTab].muxId}- style={{- aspectRatio: `${videoApps[activeTab].videoWidth} / ${videoApps[activeTab].videoHeight}`,- }}className={styles.video}poster={videoApps[activeTab].thumbnailSrc}loopplaysInline+ muted={isMuted}/>{!isPlaying && (<div className={styles.playButton}><span>βΆ</span></div>)}+ <button+ type="button"+ className={styles.muteButton}+ onClick={(e) => {+ e.stopPropagation();+ handleMuteToggle();+ }}+ >+ {isMuted ? 'π' : 'π'}+ </button></div></div><div className={styles.textContent}>diff --git a/packages/docs/static/img/homepage-showcase/submagic-thumbnail.png b/packages/docs/static/img/homepage-showcase/submagic-thumbnail.pngindex f40f68b783..416e03e80a 100644Binary files a/packages/docs/static/img/homepage-showcase/submagic-thumbnail.png and b/packages/docs/static/img/homepage-showcase/submagic-thumbnail.png differ