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.tsximport {TransitionPresentation ,TransitionPresentationComponentProps } from '@remotion/transitions'; import {Html5Audio } 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' ? <Html5Audio src ={src } /> : null} <C {...p } /> </> ); }; return {component :NewComponent , ...other , }; }
Customize the volume, offset, playback rate, and other properties of the <Html5Audio> component as you wish.
You may use it like this:
example.tsximport {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.