Skip to content

🎥 Make videos programmatically with React

audio and video volume in development

Jonny Burgerc96a8f262926
diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsx
index 357f697aa3..4a9f9a0c17 100644
--- a/packages/core/src/audio/AudioForDevelopment.tsx
+++ b/packages/core/src/audio/AudioForDevelopment.tsx
@@ -24,6 +24,15 @@ export const AudioForDevelopment: React.FC<RemotionAudioProps> = (props) => {
validateMediaProps(props, 'Audio');
+ const {volume, ...nativeProps} = props;
+
+ useEffect(() => {
+ if (!audioRef.current) {
+ return;
+ }
+ audioRef.current.volume = volume ?? 1;
+ }, [volume]);
+
useEffect(() => {
const ref = audioRef.current;
if (!ref) {
@@ -120,5 +129,5 @@ export const AudioForDevelopment: React.FC<RemotionAudioProps> = (props) => {
}
}, [absoluteFrame, currentFrame, playing, videoConfig]);
- return <audio ref={audioRef} {...props} />;
+ return <audio ref={audioRef} {...nativeProps} />;
};
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index 817f3758f7..d14c4d4b92 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -13,6 +13,8 @@ export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {
const videoConfig = useUnsafeVideoConfig();
const [playing] = usePlayingState();
+ const {volume, ...nativeProps} = props;
+
validateMediaProps(props, 'Video');
// TODO: Register as an asset
@@ -24,6 +26,13 @@ export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {
}
}, [playing]);
+ useEffect(() => {
+ if (!videoRef.current) {
+ return;
+ }
+ videoRef.current.volume = volume ?? 1;
+ }, [volume]);
+
useEffect(() => {
if (!videoRef.current) {
throw new Error('No video ref found');
@@ -52,5 +61,5 @@ export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {
}
}, [currentFrame, playing, videoConfig, absoluteFrame]);
- return <video ref={videoRef} {...props} />;
+ return <video ref={videoRef} {...nativeProps} />;
};