Skip to content

🎥 Make videos programmatically with React

Implement logging for media tags

Jonny Burger897d777bdca2
diff --git a/packages/core/src/prefetch.ts b/packages/core/src/prefetch.ts
index f641334621..8e57519e9a 100644
--- a/packages/core/src/prefetch.ts
+++ b/packages/core/src/prefetch.ts
@@ -1,5 +1,7 @@
import {useContext} from 'react';
import {getRemotionEnvironment} from './get-remotion-environment.js';
+import type {LogLevel} from './log.js';
+import {Log} from './log.js';
import {PreloadContext, setPreloads} from './prefetch-state.js';
export const usePreload = (src: string): string => {
@@ -86,9 +88,11 @@ export const prefetch = (
contentType?: string;
onProgress?: PrefetchOnProgress;
credentials?: RequestCredentials;
+ logLevel?: LogLevel;
},
): FetchAndPreload => {
const method = options?.method ?? 'blob-url';
+ const logLevel = options?.logLevel ?? 'info';
if (getRemotionEnvironment().isRendering) {
return {
@@ -97,6 +101,8 @@ export const prefetch = (
};
}
+ Log.verbose(logLevel, `[prefetch] Starting prefetch ${src}`);
+
let canceled = false;
let objectUrl: string | null = null;
let resolve: (src: string) => void = () => undefined;
@@ -175,6 +181,11 @@ export const prefetch = (
return;
}
+ Log.trace(
+ logLevel,
+ `[prefetch] Finished prefetch ${src} with method ${method}`,
+ );
+
objectUrl = url as string;
setPreloads((p) => ({
@@ -193,6 +204,7 @@ export const prefetch = (
return {
free: () => {
+ Log.trace(logLevel, `[prefetch] Freeing ${src}`);
if (objectUrl) {
if (method === 'blob-url') {
URL.revokeObjectURL(objectUrl);
diff --git a/packages/core/src/seek.ts b/packages/core/src/seek.ts
index e9c31649d7..c8d104867c 100644
--- a/packages/core/src/seek.ts
+++ b/packages/core/src/seek.ts
@@ -17,7 +17,7 @@ export const seek = ({
const timeToSet = isIosSafari() ? Number(time.toFixed(1)) : time;
Log.trace(
logLevel,
- `[seek] from ${mediaRef.currentTime} to ${timeToSet}. Reason; ${why}`,
+ `[seek] from ${mediaRef.currentTime} to ${timeToSet}. Reason: ${why}`,
);
mediaRef.currentTime = timeToSet;
diff --git a/packages/core/src/use-media-buffering.ts b/packages/core/src/use-media-buffering.ts
index 3ae74fb270..bbea31be25 100644
--- a/packages/core/src/use-media-buffering.ts
+++ b/packages/core/src/use-media-buffering.ts
@@ -1,22 +1,26 @@
import type React from 'react';
import {useEffect, useState} from 'react';
+import type {LogLevel} from './log';
+import {Log} from './log';
import {useBufferState} from './use-buffer-state';
export const useMediaBuffering = ({
element,
shouldBuffer,
isPremounting,
+ logLevel,
}: {
element: React.RefObject<HTMLVideoElement | HTMLAudioElement | null>;
shouldBuffer: boolean;
isPremounting: boolean;
+ logLevel: LogLevel;
}) => {
const buffer = useBufferState();
const [isBuffering, setIsBuffering] = useState(false);
// Buffer state based on `waiting` and `canplay`
useEffect(() => {
- let cleanupFns: Function[] = [];
+ let cleanupFns: ((reason: string) => unknown)[] = [];
const {current} = element;
if (!current) {
@@ -39,6 +43,10 @@ export const useMediaBuffering = ({
// Breaks on Firefox though: https://github.com/remotion-dev/remotion/issues/3915
if (current.readyState < current.HAVE_FUTURE_DATA) {
if (!navigator.userAgent.includes('Firefox/')) {
+ Log.trace(
+ logLevel,
+ `[load] Calling .load() on ${current.src} because readyState is ${current.readyState} and it is not Firefox. Element is premounted`,
+ );
current.load();
}
}
@@ -46,23 +54,27 @@ export const useMediaBuffering = ({
return;
}
- const cleanup = () => {
- cleanupFns.forEach((fn) => fn());
+ const cleanup = (reason: string) => {
+ cleanupFns.forEach((fn) => fn(reason));
cleanupFns = [];
setIsBuffering(false);
};
- const onWaiting = () => {
+ const blockMedia = (reason: string) => {
setIsBuffering(true);
+ Log.trace(
+ logLevel,
+ `[buffer] buffering ${current.src}. reason = ${reason}`,
+ );
const {unblock} = buffer.delayPlayback();
const onCanPlay = () => {
- cleanup();
+ cleanup('"canplay" was fired');
// eslint-disable-next-line @typescript-eslint/no-use-before-define
init();
};
const onError = () => {
- cleanup();
+ cleanup('"error" event was occurred');
// eslint-disable-next-line @typescript-eslint/no-use-before-define
init();
};
@@ -80,14 +92,20 @@ export const useMediaBuffering = ({
cleanupFns.push(() => {
current.removeEventListener('error', onError);
});
- cleanupFns.push(() => {
+ cleanupFns.push((cleanupReason) => {
+ Log.trace(
+ logLevel,
+ `unblocking ${current.src} from buffer. reason = ${cleanupReason}`,
+ );
unblock();
});
};
const init = () => {
if (current.readyState < current.HAVE_FUTURE_DATA) {
- onWaiting();
+ blockMedia(
+ `readyState is ${current.readyState}, which is less than HAVE_FUTURE_DATA`,
+ );
// Needed by iOS Safari which will not load by default
// and therefore not fire the canplay event.
@@ -99,9 +117,18 @@ export const useMediaBuffering = ({
// Breaks on Firefox though: https://github.com/remotion-dev/remotion/issues/3915
if (!navigator.userAgent.includes('Firefox/')) {
+ Log.trace(
+ logLevel,
+ `[load] Calling .load() on ${current.src} because readyState is ${current.readyState} and it is not Firefox.`,
+ );
+
current.load();
}
} else {
+ const onWaiting = () => {
+ blockMedia('"waiting" event was fired');
+ };
+
current.addEventListener('waiting', onWaiting);
cleanupFns.push(() => {
current.removeEventListener('waiting', onWaiting);
@@ -112,9 +139,9 @@ export const useMediaBuffering = ({
init();
return () => {
- cleanup();
+ cleanup('element was unmounted or prop changed');
};
- }, [buffer, element, isPremounting, shouldBuffer]);
+ }, [buffer, element, isPremounting, logLevel, shouldBuffer]);
return isBuffering;
};
diff --git a/packages/core/src/use-media-playback.ts b/packages/core/src/use-media-playback.ts
index 0786d0e919..a1dad3a455 100644
--- a/packages/core/src/use-media-playback.ts
+++ b/packages/core/src/use-media-playback.ts
@@ -92,6 +92,7 @@ export const useMediaPlayback = ({
element: mediaRef,
shouldBuffer: pauseWhenBuffering,
isPremounting,
+ logLevel,
});
const {bufferUntilFirstFrame, isBuffering} = useBufferUntilFirstFrame({
@@ -176,7 +177,7 @@ export const useMediaPlayback = ({
mediaRef: mediaRef.current,
time: shouldBeTime,
logLevel,
- why: `seeking because time shift is too big. shouldBeTime = ${shouldBeTime}, isTime = ${mediaTagTime}, requestVideoCallbackTime = ${rvcTime}, timeShift = ${timeShift}, isVariableFpsVideo = ${isVariableFpsVideo}`,
+ why: `because time shift is too big. shouldBeTime = ${shouldBeTime}, isTime = ${mediaTagTime}, requestVideoCallbackTime = ${rvcTime}, timeShift = ${timeShift}, isVariableFpsVideo = ${isVariableFpsVideo}`,
});
lastSeekDueToShift.current = lastSeek.current;
if (playing && !isVariableFpsVideo) {
diff --git a/packages/core/src/video/VideoForPreview.tsx b/packages/core/src/video/VideoForPreview.tsx
index 0c57eeb6fe..233a22d145 100644
--- a/packages/core/src/video/VideoForPreview.tsx
+++ b/packages/core/src/video/VideoForPreview.tsx
@@ -10,6 +10,8 @@ import React, {
import {SequenceContext} from '../SequenceContext.js';
import {SequenceVisibilityToggleContext} from '../SequenceManager.js';
import {useFrameForVolumeProp} from '../audio/use-audio-frame.js';
+import {useLogLevel} from '../log-level-context.js';
+import {Log} from '../log.js';
import {usePreload} from '../prefetch.js';
import {useMediaInTimeline} from '../use-media-in-timeline.js';
import {
@@ -74,6 +76,7 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
const {fps, durationInFrames} = useVideoConfig();
const parentSequence = useContext(SequenceContext);
const {hidden} = useContext(SequenceVisibilityToggleContext);
+ const logLevel = useLogLevel();
const [timelineId] = useState(() => String(Math.random()));
const isSequenceHidden = hidden[timelineId] ?? false;
@@ -139,6 +142,10 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
return videoRef.current as HTMLVideoElement;
}, []);
+ useState(() =>
+ Log.trace(logLevel, `[video] Mounting video with source = ${actualSrc}`),
+ );
+
useEffect(() => {
const {current} = videoRef;
if (!current) {
diff --git a/packages/docs/components/Installation.tsx b/packages/docs/components/Installation.tsx
index e8e169fdc6..ceec62d8c8 100644
--- a/packages/docs/components/Installation.tsx
+++ b/packages/docs/components/Installation.tsx
@@ -11,32 +11,18 @@ const LightAndDark: React.FC<{
readonly text: string;
}> = ({text}) => {
return (
- <>
- <CodeBlock
- className="shiki github-light"
- language="bash"
- style={{
- backgroundColor: 'rgb(255, 255, 255)',
- color: 'rgb(36, 41, 47)',
- }}
- >
- <div className="code-container">
- <div className="line">{text}</div>
- </div>
- </CodeBlock>
- <CodeBlock
- className="shiki github-dark"
- language="bash"
- style={{
- backgroundColor: 'rgb(13, 17, 23)',
- color: 'rgb(201, 209, 217)',
- }}
- >
- <div className="code-container">
- <div className="line">{text}</div>
- </div>
- </CodeBlock>
- </>
+ <CodeBlock
+ className="shiki github-dark"
+ language="bash"
+ style={{
+ backgroundColor: 'rgb(13, 17, 23)',
+ color: 'rgb(201, 209, 217)',
+ }}
+ >
+ <div className="code-container">
+ <div className="line">{text}</div>
+ </div>
+ </CodeBlock>
);
};
diff --git a/packages/docs/docs/player/api.mdx b/packages/docs/docs/player/api.mdx
index df1ca7afe7..0063f42b6a 100644
--- a/packages/docs/docs/player/api.mdx
+++ b/packages/docs/docs/player/api.mdx
@@ -18,15 +18,7 @@ import {Player} from '@remotion/player';
import {MyVideo} from './remotion/MyVideo';
export const App: React.FC = () => {
- return (
- <Player
- component={MyVideo}
- durationInFrames={120}
- compositionWidth={1920}
- compositionHeight={1080}
- fps={30}
- />
- );
+ return <Player component={MyVideo} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} fps={30} />;
};
```
@@ -201,16 +193,7 @@ const MyApp: React.FC = () => {
);
}, []);
- return (
- <Player
- fps={30}
- component={Component}
- durationInFrames={100}
- compositionWidth={1080}
- compositionHeight={1080}
- renderLoading={renderLoading}
- />
- );
+ return <Player fps={30} component={Component} durationInFrames={100} compositionWidth={1080} compositionHeight={1080} renderLoading={renderLoading} />;
};
```
@@ -241,38 +224,23 @@ import type {RenderPoster} from '@remotion/player';
import {Player} from '@remotion/player';
const MyApp: React.FC = () => {
- const renderPoster: RenderPoster = useCallback(
- ({height, width, isBuffering}) => {
- if (isBuffering) {
- return (
- <AbsoluteFill
- style={{justifyContent: 'center', alignItems: 'center'}}
- >
- <Spinner />
- </AbsoluteFill>
- );
- }
-
+ const renderPoster: RenderPoster = useCallback(({height, width, isBuffering}) => {
+ if (isBuffering) {
return (
- <AbsoluteFill style={{backgroundColor: 'gray'}}>
- Click to play! ({height}x{width})
+ <AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}>
+ <Spinner />
</AbsoluteFill>
);
- },
- [],
- );
+ }
- return (
- <Player
- fps={30}
- component={Component}
- durationInFrames={100}
- compositionWidth={1080}
- compositionHeight={1080}
- renderPoster={renderPoster}
- showPosterWhenUnplayed
- />
- );
+ return (
+ <AbsoluteFill style={{backgroundColor: 'gray'}}>
+ Click to play! ({height}x{width})
+ </AbsoluteFill>
+ );
+ }, []);
+
+ return <Player fps={30} component={Component} durationInFrames={100} compositionWidth={1080} compositionHeight={1080} renderPoster={renderPoster} showPosterWhenUnplayed />;
};
```
@@ -341,32 +309,20 @@ import {Player, RenderPlayPauseButton} from '@remotion/player';
import {useCallback} from 'react';
export const App: React.FC = () => {
- const renderPlayPauseButton: RenderPlayPauseButton = useCallback(
- ({playing, isBuffering}) => {
- // Since v4.0.111, isBuffering is available
- if (playing && isBuffering) {
- return <MySpinner />;
- }
-
- if (playing) {
- return <MyPlayButton />;
- }
-
- return <MyPauseButton />;
- },
- [],
- );
+ const renderPlayPauseButton: RenderPlayPauseButton = useCallback(({playing, isBuffering}) => {
+ // Since v4.0.111, isBuffering is available
+ if (playing && isBuffering) {
+ return <MySpinner />;
+ }
- return (
- <Player
- component={MyVideo}
- durationInFrames={120}
- compositionWidth={1920}
- compositionHeight={1080}
- fps={30}
- renderPlayPauseButton={renderPlayPauseButton}
- />
- );
+ if (playing) {
+ return <MyPlayButton />;
+ }
+
+ return <MyPauseButton />;
+ }, []);
+
+ return <Player component={MyVideo} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} fps={30} renderPlayPauseButton={renderPlayPauseButton} />;
};
```
@@ -389,27 +345,15 @@ import {Player, RenderFullscreenButton} from '@remotion/player';
import {useCallback} from 'react';
export const App: React.FC = () => {
- const renderFullscreenButton: RenderFullscreenButton = useCallback(
- ({isFullscreen}) => {
- if (isFullscreen) {
- return <MinimiseButton />;
- }
-
- return <FullScreenButton />;
- },
- [],
- );
+ const renderFullscreenButton: RenderFullscreenButton = useCallback(({isFullscreen}) => {
+ if (isFullscreen) {
+ return <MinimiseButton />;
+ }
- return (
- <Player
- component={MyVideo}
- durationInFrames={120}
- compositionWidth={1920}
- compositionHeight={1080}
- fps={30}
- renderFullscreenButton={renderFullscreenButton}
- />
- );
+ return <FullScreenButton />;
+ }, []);
+
+ return <Player component={MyVideo} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} fps={30} renderFullscreenButton={renderFullscreenButton} />;
};
```
@@ -439,16 +383,7 @@ export const App: React.FC = () => {
return <VolumeOnIcon />;
}, []);
- return (
- <Player
- fps={30}
- component={MyVideo}
- durationInFrames={120}
- compositionWidth={1920}
- compositionHeight={1080}
- renderMuteButton={renderMuteButton}
- />
- );
+ return <Player fps={30} component={MyVideo} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} renderMuteButton={renderMuteButton} />;
};
```
@@ -467,23 +402,11 @@ import {useCallback} from 'react';
import {Player, type RenderVolumeSlider} from '@remotion/player';
export const App: React.FC = () => {
- const renderVolumeSlider: RenderVolumeSlider = useCallback(
- ({isVertical, volume, onBlur, inputRef, setVolume}) => {
- return null; // Your volume slider implementation
- },
- [],
- );
+ const renderVolumeSlider: RenderVolumeSlider = useCallback(({isVertical, volume, onBlur, inputRef, setVolume}) => {
+ return null; // Your volume slider implementation
+ }, []);
- return (
- <Player
- fps={30}
- component={MyVideo}
- durationInFrames={120}
- compositionWidth={1920}
- compositionHeight={1080}
- renderVolumeSlider={renderVolumeSlider}
- />
- );
+ return <Player fps={30} component={MyVideo} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} renderVolumeSlider={renderVolumeSlider} />;
};
```
@@ -545,6 +468,10 @@ _optional_
A HTML class name to be used in place of the default `__remotion-player`.
+### `logLevel?`<AvailableFrom v="4.0.250" />
+
+<Options id="log" />
+
## `PlayerRef`
You may attach a ref to the player and control it in an imperative manner.
@@ -786,10 +713,7 @@ useEffect(() => {
playerRef.current.removeEventListener('pause', onPause);
playerRef.current.removeEventListener('ended', onEnded);
playerRef.current.removeEventListener('error', onError);
- playerRef.current.removeEventListener(
- 'fullscreenchange',
- onFullscreenChange,
- );
+ playerRef.current.removeEventListener('fullscreenchange', onFullscreenChange);
playerRef.current.removeEventListener('scalechange', onScaleChange);
playerRef.current.removeEventListener('mutechange', onMuteChange);
playerRef.current.removeEventListener('seeked', onSeeked);
@@ -984,16 +908,7 @@ const MyApp: React.FC = () => {
);
}, []);
- return (
- <Player
- fps={30}
- component={Component}
- durationInFrames={100}
- compositionWidth={1080}
- compositionHeight={1080}
- errorFallback={errorFallback}
- />
- );
+ return <Player fps={30} component={Component} durationInFrames={100} compositionWidth={1080} compositionHeight={1080} errorFallback={errorFallback} />;
};
```
diff --git a/packages/docs/docs/player/playback-issues.mdx b/packages/docs/docs/player/playback-issues.mdx
new file mode 100644
index 0000000000..6b13ae6c6b
--- /dev/null
+++ b/packages/docs/docs/player/playback-issues.mdx
@@ -0,0 +1,92 @@
+---
+image: /generated/articles-docs-player-playback-issues.png
+title: 'Playback issues in the <Player>'
+sidebar_label: Playback issues
+id: playback-issues
+crumb: Playback issues
+---
+
+Read this page if you encounter issues with media playback in the Player such as:
+
+- Black frames inbetween scenes
+- Audio choppiness
+- Unexpected pausing
+- Jumping around
+
+## Ensure best practices
+
+<div>
+<Step>1</Step> <span>Add <a href="/docs/player/buffer-state">`pauseWhenBuffering`</a> to `<Audio>`, `<Video>`, `<OffthreadVideo>` and `<Img>` components.</span>
+</div>
+<div>
+<Step>2</Step> <span>For seamless transitions, use the <a href="/docs/player/premounting">`premountFor`</a> prop for `<Sequence>`'s.</span>
+</div>
+<div>
+<Step>3</Step> <span>Don't use <a href="/docs/prefetch">`prefetch()`</a> if the Player is already mounted.</span>
+</div>
+<div>
+<Step>4</Step> <span>Avoid over-aggressive `prefetch()`-ing and premounting - it will use up resources faster.</span>
+</div>
+
+## Enable logging<AvailableFrom v="4.0.250"/>
+
+You can observe mounting, loading, seeking and buffering events of media by adding `logLevel="trace"` to the `<Player>` component.
+
+```tsx twoslash title='Adding logLevel="trace" to the Player'
+const otherProps = {
+ compositionHeight: 1080,
+ compositionWidth: 1920,
+ inputProps: {},
+ component: () => null,
+ fps: 30,
+ durationInFrames: 100,
+};
+
+// ---cut---
+import React from 'react';
+import {Player} from '@remotion/player';
+
+export const MyApp: React.FC = () => {
+ return <Player {...otherProps} logLevel="trace" />;
+};
+```
+
+:::note
+Don't enable this prop for production as it may lead to slowdown.
+:::
+
+To observe prefetching events, add [`logLevel: "trace"`](/docs/prefetch#options) to your [`prefetch()`](/docs/prefetch) calls, if there are any:
+
+```tsx twoslash title='Adding logLevel: "trace" to prefetch()'
+const src = 'https://example.com';
+// ---cut---
+import {prefetch} from 'remotion';
+
+prefetch(src, {
+ logLevel: 'trace',
+});
+```
+
+## Reporting issues
+
+We have implemented exact logging of relevant events so in order to improve how Remotion handles media playback.
+We are encouraging you to file feedback. If you would like to report feedback, please:
+
+<div>
+ <Step>1</Step> <span>Ensure you are at least on v4.0.250 of Remotion.</span>
+</div>
+<div>
+ <Step>2</Step>{' '}
+ <span>
+ <a href="#enable-logging">ensure you are using the best practices described above.</a>
+ </span>
+</div>
+<div>
+ <Step>3</Step>
+ <a href="#enable-logging">enable logging</a> and send all logs during playback alongside your report.
+</div>
+
+## See also
+
+- [Avoiding flickers](/docs/troubleshooting/player-flicker)
+- [Buffer state](/docs/player/buffer-state)
diff --git a/packages/docs/docs/player/thumbnail.mdx b/packages/docs/docs/player/thumbnail.mdx
index 99d13cd7c6..ea8acea54b 100644
--- a/packages/docs/docs/player/thumbnail.mdx
+++ b/packages/docs/docs/player/thumbnail.mdx
@@ -1,8 +1,8 @@
---
image: /generated/articles-docs-player-thumbnail.png
id: thumbnail
-title: "<Thumbnail>"
-crumb: "@remotion/player"
+title: '<Thumbnail>'
+crumb: '@remotion/player'
---
_available from v3.2.41_
@@ -12,12 +12,12 @@ A component which can be rendered in a regular React App (for example: for examp
```tsx twoslash title="MyApp.tsx"
// @allowUmdGlobalAccess
// @filename: ./remotion/MyVideo.tsx
-export const MyVideo: React.FC<{ title: string }> = ({ title }) => <>{title}</>;
+export const MyVideo: React.FC<{title: string}> = ({title}) => <>{title}</>;
// @filename: index.tsx
// ---cut---
-import { Thumbnail } from "@remotion/player";
-import { MyVideo } from "./remotion/MyVideo";
+import {Thumbnail} from '@remotion/player';
+import {MyVideo} from './remotion/MyVideo';
export const App: React.FC = () => {
return (
@@ -29,7 +29,7 @@ export const App: React.FC = () => {
durationInFrames={120}
fps={30}
inputProps={{
- title: "Foo",
+ title: 'Foo',
}}
/>
);
@@ -98,9 +98,9 @@ A callback function that allows you to return a custom UI that gets displayed wh
The first parameter of the callback function contains the `height` and `width` of the thumbnail as it gets rendered.
```tsx twoslash
-import { RenderLoading, Thumbnail } from "@remotion/player";
-import { useCallback } from "react";
-import { AbsoluteFill } from "remotion";
+import {RenderLoading, Thumbnail} from '@remotion/player';
+import {useCallback} from 'react';
+import {AbsoluteFill} from 'remotion';
const Component: React.FC = () => null;
@@ -108,25 +108,15 @@ const Component: React.FC = () => null;
const MyApp: React.FC = () => {
// `RenderLoading` type can be imported from "@remotion/player"
- const renderLoading: RenderLoading = useCallback(({ height, width }) => {
+ const renderLoading: RenderLoading = useCallback(({height, width}) => {
return (
- <AbsoluteFill style={{ backgroundColor: "gray" }}>
+ <AbsoluteFill style={{backgroundColor: 'gray'}}>
Loading thumbnail ({height}x{width})
</AbsoluteFill>
);
}, []);
- return (
- <Thumbnail
- fps={30}
- component={Component}
- durationInFrames={100}
- compositionWidth={1080}
- compositionHeight={1080}
- frameToDisplay={30}
- renderLoading={renderLoading}
- />
- );
+ return <Thumbnail fps={30} component={Component} durationInFrames={100} compositionWidth={1080} compositionHeight={1080} frameToDisplay={30} renderLoading={renderLoading} />;
};
```
@@ -156,6 +146,10 @@ A HTML class name to be applied to the container.
Makes the Player render things outside of the canvas. Useful if you have interactive elements in the video such as draggable elements.
+### `logLevel?`<AvailableFrom v="4.0.250" />
+
+<Options id="log" />
+
## ThumbnailRef
You may attach a ref to the thumbnail and get some layout info.
@@ -168,9 +162,9 @@ export const MyComposition: React.FC = () => null;
// @filename: index.tsx
// ---cut---
-import { Thumbnail, ThumbnailRef } from "@remotion/player";
-import { useEffect, useRef } from "react";
-import { MyComposition } from "./MyComposition";
+import {Thumbnail, ThumbnailRef} from '@remotion/player';
+import {useEffect, useRef} from 'react';
+import {MyComposition} from './MyComposition';
const MyComp: React.FC = () => {
const thumbnailRef = useRef<ThumbnailRef>(null);
@@ -203,8 +197,8 @@ The following methods are available on the thumbnail ref:
Gets the container `HTMLDivElement` of the thumbnail. Useful if you'd like to manually attach listeners to the thumbnail element.
```tsx twoslash
-import { ThumbnailRef } from "@remotion/player";
-import { useEffect, useRef } from "react";
+import {ThumbnailRef} from '@remotion/player';
+import {useEffect, useRef} from 'react';
// ---cut---
const thumbnailRef = useRef<ThumbnailRef>(null);
@@ -218,12 +212,12 @@ useEffect(() => {
}
const onClick = () => {
- console.log("thumbnail got clicked");
+ console.log('thumbnail got clicked');
};
- container.addEventListener("click", onClick);
+ container.addEventListener('click', onClick);
return () => {
- container.removeEventListener("click", onClick);
+ container.removeEventListener('click', onClick);
};
}, []);
```
@@ -245,8 +239,8 @@ Stop listening to an event. See the [Events](#events) section to see the functio
Using a [thumbnail ref](#thumbnailref), you can bind event listeners to get notified of certain events of the thumbnail.
```tsx twoslash
-import { ThumbnailRef } from "@remotion/player";
-import { useEffect, useRef } from "react";
+import {ThumbnailRef} from '@remotion/player';
+import {useEffect, useRef} from 'react';
// ---cut---
const thumbnailRef = useRef<ThumbnailRef>(null);
@@ -255,8 +249,8 @@ useEffect(() => {
return;
}
- thumbnailRef.current.addEventListener("error", (e) => {
- console.log("error", e.detail.error);
+ thumbnailRef.current.addEventListener('error', (e) => {
+ console.log('error', e.detail.error);
});
}, []);
```
@@ -268,12 +262,12 @@ Fires when an error or uncaught exception has happened in the thumbnail.
You may get the error by reading the `e.detail.error` value:
```tsx twoslash
-import { ThumbnailRef } from "@remotion/player";
-import { useRef } from "react";
+import {ThumbnailRef} from '@remotion/player';
+import {useRef} from 'react';
const ref = useRef<ThumbnailRef>(null);
// ---cut---
-ref.current?.addEventListener("error", (e) => {
- console.log("error ", e.detail.error); // error [Error: undefined is not a function]
+ref.current?.addEventListener('error', (e) => {
+ console.log('error ', e.detail.error); // error [Error: undefined is not a function]
});
```
@@ -302,8 +296,8 @@ See: [`<Player>` -> Handling errors](/docs/player/player#handling-errors)
<Credits
contributors={[
{
- username: "Slashgear",
- contribution: "Implementation",
+ username: 'Slashgear',
+ contribution: 'Implementation',
},
]}
/>
diff --git a/packages/docs/docs/prefetch.mdx b/packages/docs/docs/prefetch.mdx
index 66da767d00..f0ced5d3ca 100644
--- a/packages/docs/docs/prefetch.mdx
+++ b/packages/docs/docs/prefetch.mdx
@@ -18,13 +18,10 @@ Remote assets need to support [CORS](https://developer.mozilla.org/en-US/docs/We
<summary>More info</summary>
<ul>
<li>
- Remotion's origin is usually <code>http://localhost:3000</code>, but it
- may be different if rendering on Lambda or the port is busy.
+ Remotion's origin is usually <code>http://localhost:3000</code>, but it may be different if rendering on Lambda or the port is busy.
</li>
<li>
- You can{' '}
- <a href="/docs/chromium-flags#--disable-web-security">disable CORS</a>{' '}
- during renders.
+ You can <a href="/docs/chromium-flags#--disable-web-security">disable CORS</a> during renders.
</li>
</ul>
</details>
@@ -51,11 +48,9 @@ An alternative to `prefetch()` are the [`@remotion/preload`](/docs/preload) APIs
## API
-## Arguments
-
### `src`
-The function takes a `src`, which can be a remote URL, an imported asset or an asset loaded using [`staticFile()`](/docs/staticfile) (see: [Importing assets](/docs/assets)). Once called, prefetching starts and an object with two properties are returned:
+The function takes a `src`, which can be a remote URL, an imported asset or an asset loaded using [`staticFile()`](/docs/staticfile) (see: [Importing assets](/docs/assets)).
### `options`
@@ -94,10 +89,7 @@ const onProgress: PrefetchOnProgress = (progress) => {
return;
}
- console.log(
- 'Loading progress:',
- Math.round(progress.loadedBytes / progress.totalBytes / 100) + '%',
- );
+ console.log('Loading progress:', Math.round(progress.loadedBytes / progress.totalBytes / 100) + '%');
};
prefetch('https://example.com/video.mp4', {
@@ -105,9 +97,13 @@ prefetch('https://example.com/video.mp4', {
});
```
+### `logLevel?`<AvailableFrom v="4.0.250" />
+
+<Options id="log" />
+
## Return value
-An object with:
+Once called, prefetching starts and an object with two properties are returned:
### `free()`
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 7d124e519a..1e70c09b08 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -3234,6 +3234,15 @@ export const articles = [
noAi: false,
slug: 'player/media-keys',
},
+ {
+ id: 'playback-issues',
+ title: 'Playback issues in the <Player>',
+ relativePath: 'docs/player/playback-issues.mdx',
+ compId: 'articles-docs-player-playback-issues',
+ crumb: 'Playback issues',
+ noAi: false,
+ slug: 'player/playback-issues',
+ },
{
id: 'examples',
title: 'Examples for @remotion/player',
diff --git a/packages/docs/static/generated/articles-docs-player-playback-issues.png b/packages/docs/static/generated/articles-docs-player-playback-issues.png
new file mode 100644
index 0000000000..5f57d40eea
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-player-playback-issues.png differ
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index e3c6700823..06c87a9e46 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -320,6 +320,13 @@ const PlayerFn = <
useImperativeHandle(ref, () => rootRef.current as PlayerRef, []);
+ useState(() => {
+ Internals.Log.trace(
+ logLevel,
+ `[player] Mounting <Player>. User agent = ${navigator.userAgent}`,
+ );
+ });
+
const timelineContextValue = useMemo((): TimelineContextValue => {
return {
frame,
diff --git a/packages/renderer/src/log-level.ts b/packages/renderer/src/log-level.ts
index 11fa2280fe..3267d4ce45 100644
--- a/packages/renderer/src/log-level.ts
+++ b/packages/renderer/src/log-level.ts
@@ -1,4 +1,4 @@
-export const logLevels = ['verbose', 'info', 'warn', 'error'] as const;
+export const logLevels = ['trace', 'verbose', 'info', 'warn', 'error'] as const;
export type LogLevel = (typeof logLevels)[number];
diff --git a/packages/renderer/src/options/log-level.tsx b/packages/renderer/src/options/log-level.tsx
index dbe48b83a3..947b14ac01 100644
--- a/packages/renderer/src/options/log-level.tsx
+++ b/packages/renderer/src/options/log-level.tsx
@@ -12,11 +12,10 @@ export const logLevelOption = {
ssrName: 'logLevel',
description: () => (
<>
- One of <code>verbose</code>, <code>info</code>, <code>warn</code>,{' '}
- <code>error</code>.<br /> Determines how much is being logged to the
- console.
- <br /> <code>verbose</code> will also log <code>console.log</code>
- {"'"}s from the browser.
+ One of <code>trace</code>, <code>verbose</code>, <code>info</code>,{' '}
+ <code>warn</code>, <code>error</code>.<br /> Determines how much info is
+ being logged to the console.
+ <br />
<br /> Default <code>info</code>.
</>
),