🎥 Make videos programmatically with React
`remotion`: Add `MediaPlaybackError` custom error class with `src` field
Jonny Burgerdd6bced898ff
diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 5731755230..3bdb5133ed 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -203,6 +203,7 @@ export {RemotionVideoProps,Video,} from './video/index.js';+export {MediaPlaybackError} from './video/MediaPlaybackError.js';export type {OnVideoFrame} from './video/props.js';export type {VolumeProp} from './volume-prop.js';export {watchStaticFile} from './watch-static-file.js';diff --git a/packages/core/src/video/MediaPlaybackError.ts b/packages/core/src/video/MediaPlaybackError.tsnew file mode 100644index 0000000000..c87f64649e--- /dev/null+++ b/packages/core/src/video/MediaPlaybackError.ts@@ -0,0 +1,9 @@+export class MediaPlaybackError extends Error {+ readonly src: string;++ constructor({message, src}: {message: string; src: string}) {+ super(message);+ this.name = 'MediaPlaybackError';+ this.src = src;+ }+}diff --git a/packages/core/src/video/VideoForPreview.tsx b/packages/core/src/video/VideoForPreview.tsxindex 642640a471..db80e5cf78 100644--- a/packages/core/src/video/VideoForPreview.tsx+++ b/packages/core/src/video/VideoForPreview.tsx@@ -30,6 +30,7 @@ import {import {evaluateVolume} from '../volume-prop.js';import {warnAboutTooHighVolume} from '../volume-safeguard.js';import {useEmitVideoFrame} from './emit-video-frame.js';+import {MediaPlaybackError} from './MediaPlaybackError.js';import type {NativeVideoProps, OnVideoFrame, RemotionVideoProps} from './props';import {isIosSafari, useAppendVideoFragment} from './video-fragment.js';@@ -245,27 +246,33 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<// If user is handling the error, we don't cause an unhandled exceptionif (onError) {- const err = new Error(- `Code ${current.error.code}: ${current.error.message}`,- );+ const err = new MediaPlaybackError({+ message: `Code ${current.error.code}: ${current.error.message}`,+ src: src as string,+ });onError(err);return;}- throw new Error(- `The browser threw an error while playing the video ${src}: Code ${current.error.code} - ${current?.error?.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`,- );+ throw new MediaPlaybackError({+ message: `The browser threw an error while playing the video ${src}: Code ${current.error.code} - ${current?.error?.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`,+ src: src as string,+ });} else {// If user is handling the error, we don't cause an unhandled exceptionif (onError) {- const err = new Error(- `The browser threw an error while playing the video ${src}`,- );+ const err = new MediaPlaybackError({+ message: `The browser threw an error while playing the video ${src}`,+ src: src as string,+ });onError(err);return;}- throw new Error('The browser threw an error while playing the video');+ throw new MediaPlaybackError({+ message: 'The browser threw an error while playing the video',+ src: src as string,+ });}};diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsxindex 6748b18562..d61fdbeffc 100644--- a/packages/core/src/video/VideoForRendering.tsx+++ b/packages/core/src/video/VideoForRendering.tsx@@ -26,6 +26,7 @@ import {useUnsafeVideoConfig} from '../use-unsafe-video-config.js';import {evaluateVolume} from '../volume-prop.js';import {warnAboutTooHighVolume} from '../volume-safeguard.js';import {getMediaTime} from './get-current-time.js';+import {MediaPlaybackError} from './MediaPlaybackError.js';import type {OnVideoFrame, RemotionVideoProps} from './props';import {seekToTimeMultipleUntilRight} from './seek-until-right.js';@@ -223,11 +224,15 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<return;}- throw new Error(- `The browser threw an error while playing the video ${props.src}: Code ${current.error.code} - ${current?.error?.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`,- );+ throw new MediaPlaybackError({+ message: `The browser threw an error while playing the video ${props.src}: Code ${current.error.code} - ${current?.error?.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`,+ src: props.src as string,+ });} else {- throw new Error('The browser threw an error');+ throw new MediaPlaybackError({+ message: 'The browser threw an error',+ src: props.src as string,+ });}};