Skip to content

🎥 Make videos programmatically with React

Update prefetch.ts

Jonny Burger1d45f6ac92cf
diff --git a/packages/core/src/prefetch.ts b/packages/core/src/prefetch.ts
index fc58cc14b8..1bd78f4d15 100644
--- a/packages/core/src/prefetch.ts
+++ b/packages/core/src/prefetch.ts
@@ -38,6 +38,7 @@ export const prefetch = (
src: string,
options?: {
method?: 'blob-url' | 'base64';
+ contentType?: string;
},
): FetchAndPreload => {
const method = options?.method ?? 'blob-url';
@@ -82,11 +83,25 @@ export const prefetch = (
return;
}
+ if (
+ !buf.type.startsWith('video/') &&
+ !buf.type.startsWith('audio/') &&
+ !options?.contentType
+ ) {
+ console.warn(
+ `Called prefetch() on ${src} which returned a "Content-Type" of ${buf.type}. Prefetched content should have a proper content type (video/... or audio/...) or a contentType passed the options of prefetch(). Otherwise, prefetching will not work properly in all browsers.`,
+ );
+ }
+
+ const actualBlob = options?.contentType
+ ? new Blob([buf], {type: options.contentType})
+ : buf;
+
if (method === 'base64') {
- return blobToBase64(buf);
+ return blobToBase64(actualBlob);
}
- return URL.createObjectURL(buf);
+ return URL.createObjectURL(actualBlob);
})
.then((url) => {
if (canceled) {