fix(android): local asset for android in release (#4784)

* fix: hermes path for android release

* chore: update bun.lock

* fix: handle raw ressources in Android release mode

* fix: replace custom AppContextHolder logic with NitroModules.applicationContext
This commit is contained in:
Thibault Capelli
2025-12-18 13:19:27 +01:00
committed by GitHub
parent 39f88c8b05
commit 00a6b19736
4 changed files with 34 additions and 3 deletions
+1
View File
@@ -1,5 +1,6 @@
{ {
"lockfileVersion": 1, "lockfileVersion": 1,
"configVersion": 0,
"workspaces": { "workspaces": {
"": { "": {
"name": "react-native-video-monorepo", "name": "react-native-video-monorepo",
+1 -1
View File
@@ -45,7 +45,7 @@ react {
/* Hermes Commands */ /* Hermes Commands */
// The hermes compiler command to run. By default it is 'hermesc' // The hermes compiler command to run. By default it is 'hermesc'
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" hermesCommand = "$rootDir/../../node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc"
// //
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"] // hermesFlags = ["-O", "-output-source-map"]
@@ -1,12 +1,43 @@
package com.margelo.nitro.video package com.margelo.nitro.video
import android.content.Context
import android.net.Uri
import androidx.media3.common.MediaItem
import androidx.media3.datasource.RawResourceDataSource
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.proguard.annotations.DoNotStrip import com.facebook.proguard.annotations.DoNotStrip
import com.margelo.nitro.NitroModules
@DoNotStrip @DoNotStrip
class HybridVideoPlayerSourceFactory: HybridVideoPlayerSourceFactorySpec() { class HybridVideoPlayerSourceFactory: HybridVideoPlayerSourceFactorySpec() {
private val applicationContext: Context
get() = NitroModules.applicationContext
?: throw IllegalStateException(
"NitroModules.applicationContext has not been initialized."
)
private fun normalizeUri(input: String): String {
val parsedUri = Uri.parse(input)
if (parsedUri.scheme != null) {
return parsedUri.toString()
}
val resId = applicationContext.resources
.getIdentifier(input, "raw", applicationContext.packageName)
if (resId == 0) {
throw IllegalArgumentException("The video resource '$input' could not be found in res/raw")
}
val mediaUri = RawResourceDataSource.buildRawResourceUri(resId)
return mediaUri.toString()
}
override fun fromUri(uri: String): HybridVideoPlayerSourceSpec { override fun fromUri(uri: String): HybridVideoPlayerSourceSpec {
val config = NativeVideoConfig( val config = NativeVideoConfig(
uri = uri, uri = normalizeUri(uri),
externalSubtitles = null, externalSubtitles = null,
drm = null, drm = null,
headers = null, headers = null,
@@ -7,7 +7,6 @@ import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager import com.facebook.react.uimanager.ViewManager
class VideoPackage : ReactPackage { class VideoPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return emptyList() return emptyList()