Transitioning with audio
working from v4.0.58
To add sound to a transition, you may use this function to wrap any presentation:
add-sound.tsxtsx
import {TransitionPresentation ,TransitionPresentationComponentProps ,} from "@remotion/transitions";import {Audio } from "remotion";export functionaddSound <T extendsRecord <string, unknown>>(transition :TransitionPresentation <T >,src : string,):TransitionPresentation <T > {const {component :Component , ...other } =transition ;constC =Component asReact .FC <TransitionPresentationComponentProps <T >>;constNewComponent :React .FC <TransitionPresentationComponentProps <T >> = (p ,) => {return (<>{p .presentationDirection === "entering" ? <Audio src ={src } /> : null}<C {...p } /></>);};return {component :NewComponent ,...other ,};}
add-sound.tsxtsx
import {TransitionPresentation ,TransitionPresentationComponentProps ,} from "@remotion/transitions";import {Audio } from "remotion";export functionaddSound <T extendsRecord <string, unknown>>(transition :TransitionPresentation <T >,src : string,):TransitionPresentation <T > {const {component :Component , ...other } =transition ;constC =Component asReact .FC <TransitionPresentationComponentProps <T >>;constNewComponent :React .FC <TransitionPresentationComponentProps <T >> = (p ,) => {return (<>{p .presentationDirection === "entering" ? <Audio src ={src } /> : null}<C {...p } /></>);};return {component :NewComponent ,...other ,};}
Customize the volume, offset, playback rate, and other properties of the <Audio>
component as you wish.
You may use it like this:
example.tsxtsx
import {slide } from "@remotion/transitions/slide";import {staticFile } from "remotion";constpresentation =slide ();constwithSound =addSound (presentation ,staticFile ("whoosh.mp3"));
example.tsxtsx
import {slide } from "@remotion/transitions/slide";import {staticFile } from "remotion";constpresentation =slide ();constwithSound =addSound (presentation ,staticFile ("whoosh.mp3"));
Now you can use withSound
in place of presentation
.