Skip to content

🎥 Make videos programmatically with React

onlyWarnForMediaSeekingError + updated docs

Jonny Burger7cd632cd6ef4
diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsx
index c9fff22e46..342a3271c7 100644
--- a/packages/core/src/audio/AudioForDevelopment.tsx
+++ b/packages/core/src/audio/AudioForDevelopment.tsx
@@ -66,6 +66,7 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
src: nativeProps.src,
mediaType: 'audio',
playbackRate: playbackRate ?? 1,
+ onlyWarnForMediaSeekingError: false,
});
useImperativeHandle(ref, () => {
diff --git a/packages/core/src/use-media-playback.ts b/packages/core/src/use-media-playback.ts
index ae050e4081..27030f2858 100644
--- a/packages/core/src/use-media-playback.ts
+++ b/packages/core/src/use-media-playback.ts
@@ -13,11 +13,13 @@ export const useMediaPlayback = ({
src,
mediaType,
playbackRate: localPlaybackRate,
+ onlyWarnForMediaSeekingError,
}: {
mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>;
src: string | undefined;
mediaType: 'audio' | 'video';
playbackRate: number;
+ onlyWarnForMediaSeekingError: boolean;
}) => {
const {playbackRate: globalPlaybackRate} = useContext(TimelineContext);
const frame = useCurrentFrame();
@@ -68,7 +70,12 @@ export const useMediaPlayback = ({
// If scrubbing around, adjust timing
// or if time shift is bigger than 0.2sec
mediaRef.current.currentTime = shouldBeTime;
- warnAboutNonSeekableMedia(mediaRef.current, 'console');
+ if (!onlyWarnForMediaSeekingError) {
+ warnAboutNonSeekableMedia(
+ mediaRef.current,
+ onlyWarnForMediaSeekingError ? 'console-warning' : 'console-error'
+ );
+ }
}
if (!playing || absoluteFrame === 0) {
@@ -91,5 +98,6 @@ export const useMediaPlayback = ({
src,
mediaStartsAt,
localPlaybackRate,
+ onlyWarnForMediaSeekingError,
]);
};
diff --git a/packages/core/src/video/OffthreadVideo.tsx b/packages/core/src/video/OffthreadVideo.tsx
index e67c695c77..8ebff4a978 100644
--- a/packages/core/src/video/OffthreadVideo.tsx
+++ b/packages/core/src/video/OffthreadVideo.tsx
@@ -37,5 +37,5 @@ export const OffthreadVideo: React.FC<
return <OffthreadVideoForRendering {...otherProps} />;
}
- return <VideoForDevelopment {...otherProps} />;
+ return <VideoForDevelopment onlyWarnForMediaSeekingError {...otherProps} />;
};
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsx
index 4ac1a25356..9bfa741b1c 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/Video.tsx
@@ -40,7 +40,13 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
return <VideoForRendering {...otherProps} ref={ref} />;
}
- return <VideoForDevelopment {...otherProps} ref={ref} />;
+ return (
+ <VideoForDevelopment
+ onlyWarnForMediaSeekingError={false}
+ {...otherProps}
+ ref={ref}
+ />
+ );
};
export const Video = forwardRef(VideoForwardingFunction);
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index ba84123975..e07894803a 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -12,7 +12,9 @@ import type {RemotionVideoProps} from './props';
const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
HTMLVideoElement,
- RemotionVideoProps
+ RemotionVideoProps & {
+ onlyWarnForMediaSeekingError: boolean;
+ }
> = (props, ref) => {
const videoRef = useRef<HTMLVideoElement>(null);
@@ -46,6 +48,7 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
src: nativeProps.src,
mediaType: 'video',
playbackRate: props.playbackRate ?? 1,
+ onlyWarnForMediaSeekingError: props.onlyWarnForMediaSeekingError,
});
useImperativeHandle(ref, () => {
diff --git a/packages/core/src/warn-about-non-seekable-media.ts b/packages/core/src/warn-about-non-seekable-media.ts
index 45fac20581..51516d980d 100644
--- a/packages/core/src/warn-about-non-seekable-media.ts
+++ b/packages/core/src/warn-about-non-seekable-media.ts
@@ -2,7 +2,7 @@ const alreadyWarned: {[key: string]: boolean} = {};
export const warnAboutNonSeekableMedia = (
ref: HTMLMediaElement,
- type: 'console' | 'exception'
+ type: 'console-warning' | 'console-error' | 'exception'
) => {
// Media is not loaded yet, but this does not yet mean something is wrong with the media
@@ -23,8 +23,12 @@ export const warnAboutNonSeekableMedia = (
if (range.start === 0 && range.end === 0) {
const msg = `The media does not seem to support seeking. Remotion cannot properly handle it. Please see https://remotion.dev/docs/non-seekable-media for assistance. Source: ${ref.src}`;
- if (type === 'console') {
+ if (type === 'console-error') {
console.error(msg);
+ } else if (type === 'console-warning') {
+ console.warn(
+ `The media ${ref.src} does not seem to support seeking. The video will render fine, but may not play correctly in preview and in the <Player> See https://remotion.dev/docs/non-seekable-media for an explanation.`
+ );
} else {
throw new Error(msg);
}
diff --git a/packages/docs/docs/non-seekable-media.md b/packages/docs/docs/non-seekable-media.md
index de9b4d74bd..0b93015c40 100644
--- a/packages/docs/docs/non-seekable-media.md
+++ b/packages/docs/docs/non-seekable-media.md
@@ -9,16 +9,21 @@ If you see the following error in the console:
The media [URL] does not seem to support seeking. Remotion cannot properly handle it. Please see https://remotion.dev/docs/non-seekable-media for assistance.
```
-it means you have provided a video or audio that cannot be seeked to an arbitrary time. The cause for this is that when requesting the audio file, no `Content-Range` HTTP header has been sent by the server, making it impossible for the browser and therefore for Remotion to seek the media.
+it means you have provided a video or audio that cannot be seeked to an arbitrary time.
+The cause for this is that when requesting the media file, either:
+
+- No `Content-Range` HTTP header has been sent by the server, making it impossible for the browser and therefore for Remotion to seek the media.
+- No `Content-Length` HTTP header has been sent by the server.
+- The file does not support [Faststart](https://www.videoconverterfactory.com/tips/mp4-fast-start.html)
## Reproduction
You can verify that this is the problem by opening the video or audio in a new tab and observe that you cannot seek the media.
-So far, this behavior has been observed when serving media from a private Google Cloud Storage bucket.
-
-## Solution
+## Solutions
-To fix this problem, you need to serve the media from a webhost that supports the `Range` header.
+Choose one of those solutions:
-Alternatively, you can download the media and import it locally using an `import` or `require()` statement.
+- Serve the media from a webhost that supports the `Range` header and returns a `Content-Length` and `Content-Range` header.
+- Download the media and import it locally using an `import` or `require()` statement.
+- Use the [`<OffthreadVideo>`](/docs/offthreadvideo) component which will render the video fine. You may still see problems during playback in the preview or the [`<Player>`](/docs/player)