Skip to content

Commit

Permalink
fix(android): disable caching on local asset files (#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeboub authored Dec 1, 2024
1 parent 569a79c commit 63c592f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions android/src/main/java/com/brentvatne/common/api/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Source {
/** Parsed value of source to playback */
var uri: Uri? = null

/** True if source is a local JS asset */
var isLocalAssetFile: Boolean = false

/** True if source is a local file asset://, ... */
var isAsset: Boolean = false

/** Start position of playback used to resume playback */
var startPositionMs: Int = -1

Expand Down Expand Up @@ -101,6 +107,8 @@ class Source {
sideLoadedTextTracks == other.sideLoadedTextTracks &&
adsProps == other.adsProps &&
minLoadRetryCount == other.minLoadRetryCount &&
isLocalAssetFile == other.isLocalAssetFile &&
isAsset == other.isAsset &&
bufferConfig == other.bufferConfig
)
}
Expand Down Expand Up @@ -157,6 +165,8 @@ class Source {
companion object {
private const val TAG = "Source"
private const val PROP_SRC_URI = "uri"
private const val PROP_SRC_IS_LOCAL_ASSET_FILE = "isLocalAssetFile"
private const val PROP_SRC_IS_ASSET = "isAsset"
private const val PROP_SRC_START_POSITION = "startPosition"
private const val PROP_SRC_CROP_START = "cropStart"
private const val PROP_SRC_CROP_END = "cropEnd"
Expand Down Expand Up @@ -223,6 +233,8 @@ class Source {
}
source.uriString = uriString
source.uri = uri
source.isLocalAssetFile = safeGetBool(src, PROP_SRC_IS_LOCAL_ASSET_FILE, false)
source.isAsset = safeGetBool(src, PROP_SRC_IS_ASSET, false)
source.startPositionMs = safeGetInt(src, PROP_SRC_START_POSITION, -1)
source.cropStartMs = safeGetInt(src, PROP_SRC_CROP_START, -1)
source.cropEndMs = safeGetInt(src, PROP_SRC_CROP_END, -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ private void initializePlayer() {
// Initialize core configuration and listeners
initializePlayerCore(self);
}
if (source.getBufferConfig().getCacheSize() > 0) {
if (!source.isLocalAssetFile() && !source.isAsset() && source.getBufferConfig().getCacheSize() > 0) {
RNVSimpleCache.INSTANCE.setSimpleCache(
this.getContext(),
source.getBufferConfig().getCacheSize()
Expand Down Expand Up @@ -1186,7 +1186,7 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessi
DataSource.Factory assetDataSourceFactory = DataSourceUtil.buildAssetDataSourceFactory(themedReactContext, uri);
mediaSourceFactory = new ProgressiveMediaSource.Factory(assetDataSourceFactory);
} catch (Exception e) {
throw new IllegalStateException("cannot open input file" + uri);
throw new IllegalStateException("cannot open input file:" + uri);
}
} else if ("file".equals(uri.getScheme()) ||
!useCache) {
Expand Down
2 changes: 2 additions & 0 deletions examples/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"start:tv": "EXPO_TV=1 expo start",
"android:tv": "EXPO_TV=1 expo run:android",
"android": "EXPO_TV=0 expo run:android",
"release:android": "cd android && EXPO_TV=0 ./gradlew assembleRelease && cd -",
"release:android:tv": "cd android && EXPO_TV=1 ./gradlew assembleRelease && cd -",
"ios:tv": "EXPO_TV=1 expo run:ios",
"ios": "EXPO_TV=0 expo run:ios",
"web": "expo start --web",
Expand Down
6 changes: 6 additions & 0 deletions src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!_source) {
return undefined;
}

const isLocalAssetFile =
typeof _source === 'number' ||
('uri' in _source && typeof _source.uri === 'number');

const resolvedSource = resolveAssetSourceForVideo(_source);
let uri = resolvedSource.uri || '';
if (uri && uri.match(/^\//)) {
Expand Down Expand Up @@ -226,6 +231,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
uri,
isNetwork,
isAsset,
isLocalAssetFile,
shouldCache: resolvedSource.shouldCache || false,
type: resolvedSource.type || '',
mainVer: resolvedSource.mainVer || 0,
Expand Down
1 change: 1 addition & 0 deletions src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type VideoSrc = Readonly<{
uri?: string;
isNetwork?: boolean;
isAsset?: boolean;
isLocalAssetFile?: boolean;
shouldCache?: boolean;
type?: string;
mainVer?: Int32;
Expand Down
1 change: 1 addition & 0 deletions src/types/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type ReactVideoSourceProperties = {
uri?: string;
isNetwork?: boolean;
isAsset?: boolean;
isLocalAssetFile?: boolean;
shouldCache?: boolean;
type?: string;
mainVer?: number;
Expand Down

0 comments on commit 63c592f

Please sign in to comment.