mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-06-01 10:35:49 +00:00
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:
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "react-native-video-monorepo",
|
"name": "react-native-video-monorepo",
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
|||||||
+32
-1
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user