From ccf9497313d6bf58ebef2bb06d1f5de71704339a Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 14 Oct 2025 12:09:16 +0200 Subject: [PATCH] Add optional `mimeType` string in source object --- .../src/core/VideoPlayer.web.ts | 22 +++++++++++++------ .../src/core/types/VideoConfig.ts | 5 +++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/react-native-video/src/core/VideoPlayer.web.ts b/packages/react-native-video/src/core/VideoPlayer.web.ts index 22bf3d3a..822505be 100644 --- a/packages/react-native-video/src/core/VideoPlayer.web.ts +++ b/packages/react-native-video/src/core/VideoPlayer.web.ts @@ -234,19 +234,27 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase { | NoAutocomplete | null, ): Promise { - const src = - typeof source === "object" && source && "uri" in source - ? source.uri - : source; - if (typeof src === "number") { + if (!source) { + this.player.src([]); + this.player.reset(); + return; + } + + if (typeof source === "number") { console.error( "A source uri must be a string. Numbers are only supported on native.", ); return; } + if (typeof source === "string") { + source = { uri: source }; + } // TODO: handle start time - this.player.src(src); - if (typeof source !== "object") return; + this.player.src({ + src: source.uri, + type: source.mimeType, + }); + if (source.initializeOnCreation) await this.preload(); } // Text Track Management diff --git a/packages/react-native-video/src/core/types/VideoConfig.ts b/packages/react-native-video/src/core/types/VideoConfig.ts index 60633005..6024ab6d 100644 --- a/packages/react-native-video/src/core/types/VideoConfig.ts +++ b/packages/react-native-video/src/core/types/VideoConfig.ts @@ -14,6 +14,11 @@ export type VideoConfig = { * ``` */ uri: VideoSource; + /** + * complete mime type, used to select a background for playback. + * if not specified, the extension of the url might be used + */ + mimeType?: string /** * The headers to be sent with the request. */