fix(android): disable caching on local asset files (#4304)
This commit is contained in:
parent
569a79c510
commit
63c592f7cd
@ -30,6 +30,12 @@ class Source {
|
|||||||
/** Parsed value of source to playback */
|
/** Parsed value of source to playback */
|
||||||
var uri: Uri? = null
|
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 */
|
/** Start position of playback used to resume playback */
|
||||||
var startPositionMs: Int = -1
|
var startPositionMs: Int = -1
|
||||||
|
|
||||||
@ -101,6 +107,8 @@ class Source {
|
|||||||
sideLoadedTextTracks == other.sideLoadedTextTracks &&
|
sideLoadedTextTracks == other.sideLoadedTextTracks &&
|
||||||
adsProps == other.adsProps &&
|
adsProps == other.adsProps &&
|
||||||
minLoadRetryCount == other.minLoadRetryCount &&
|
minLoadRetryCount == other.minLoadRetryCount &&
|
||||||
|
isLocalAssetFile == other.isLocalAssetFile &&
|
||||||
|
isAsset == other.isAsset &&
|
||||||
bufferConfig == other.bufferConfig
|
bufferConfig == other.bufferConfig
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -157,6 +165,8 @@ class Source {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "Source"
|
private const val TAG = "Source"
|
||||||
private const val PROP_SRC_URI = "uri"
|
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_START_POSITION = "startPosition"
|
||||||
private const val PROP_SRC_CROP_START = "cropStart"
|
private const val PROP_SRC_CROP_START = "cropStart"
|
||||||
private const val PROP_SRC_CROP_END = "cropEnd"
|
private const val PROP_SRC_CROP_END = "cropEnd"
|
||||||
@ -223,6 +233,8 @@ class Source {
|
|||||||
}
|
}
|
||||||
source.uriString = uriString
|
source.uriString = uriString
|
||||||
source.uri = uri
|
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.startPositionMs = safeGetInt(src, PROP_SRC_START_POSITION, -1)
|
||||||
source.cropStartMs = safeGetInt(src, PROP_SRC_CROP_START, -1)
|
source.cropStartMs = safeGetInt(src, PROP_SRC_CROP_START, -1)
|
||||||
source.cropEndMs = safeGetInt(src, PROP_SRC_CROP_END, -1)
|
source.cropEndMs = safeGetInt(src, PROP_SRC_CROP_END, -1)
|
||||||
|
@ -747,7 +747,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
// Initialize core configuration and listeners
|
// Initialize core configuration and listeners
|
||||||
initializePlayerCore(self);
|
initializePlayerCore(self);
|
||||||
}
|
}
|
||||||
if (source.getBufferConfig().getCacheSize() > 0) {
|
if (!source.isLocalAssetFile() && !source.isAsset() && source.getBufferConfig().getCacheSize() > 0) {
|
||||||
RNVSimpleCache.INSTANCE.setSimpleCache(
|
RNVSimpleCache.INSTANCE.setSimpleCache(
|
||||||
this.getContext(),
|
this.getContext(),
|
||||||
source.getBufferConfig().getCacheSize()
|
source.getBufferConfig().getCacheSize()
|
||||||
@ -1186,7 +1186,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
DataSource.Factory assetDataSourceFactory = DataSourceUtil.buildAssetDataSourceFactory(themedReactContext, uri);
|
DataSource.Factory assetDataSourceFactory = DataSourceUtil.buildAssetDataSourceFactory(themedReactContext, uri);
|
||||||
mediaSourceFactory = new ProgressiveMediaSource.Factory(assetDataSourceFactory);
|
mediaSourceFactory = new ProgressiveMediaSource.Factory(assetDataSourceFactory);
|
||||||
} catch (Exception e) {
|
} 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()) ||
|
} else if ("file".equals(uri.getScheme()) ||
|
||||||
!useCache) {
|
!useCache) {
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
"start:tv": "EXPO_TV=1 expo start",
|
"start:tv": "EXPO_TV=1 expo start",
|
||||||
"android:tv": "EXPO_TV=1 expo run:android",
|
"android:tv": "EXPO_TV=1 expo run:android",
|
||||||
"android": "EXPO_TV=0 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:tv": "EXPO_TV=1 expo run:ios",
|
||||||
"ios": "EXPO_TV=0 expo run:ios",
|
"ios": "EXPO_TV=0 expo run:ios",
|
||||||
"web": "expo start --web",
|
"web": "expo start --web",
|
||||||
|
@ -151,6 +151,11 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
if (!_source) {
|
if (!_source) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLocalAssetFile =
|
||||||
|
typeof _source === 'number' ||
|
||||||
|
('uri' in _source && typeof _source.uri === 'number');
|
||||||
|
|
||||||
const resolvedSource = resolveAssetSourceForVideo(_source);
|
const resolvedSource = resolveAssetSourceForVideo(_source);
|
||||||
let uri = resolvedSource.uri || '';
|
let uri = resolvedSource.uri || '';
|
||||||
if (uri && uri.match(/^\//)) {
|
if (uri && uri.match(/^\//)) {
|
||||||
@ -226,6 +231,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
uri,
|
uri,
|
||||||
isNetwork,
|
isNetwork,
|
||||||
isAsset,
|
isAsset,
|
||||||
|
isLocalAssetFile,
|
||||||
shouldCache: resolvedSource.shouldCache || false,
|
shouldCache: resolvedSource.shouldCache || false,
|
||||||
type: resolvedSource.type || '',
|
type: resolvedSource.type || '',
|
||||||
mainVer: resolvedSource.mainVer || 0,
|
mainVer: resolvedSource.mainVer || 0,
|
||||||
|
@ -35,6 +35,7 @@ export type VideoSrc = Readonly<{
|
|||||||
uri?: string;
|
uri?: string;
|
||||||
isNetwork?: boolean;
|
isNetwork?: boolean;
|
||||||
isAsset?: boolean;
|
isAsset?: boolean;
|
||||||
|
isLocalAssetFile?: boolean;
|
||||||
shouldCache?: boolean;
|
shouldCache?: boolean;
|
||||||
type?: string;
|
type?: string;
|
||||||
mainVer?: Int32;
|
mainVer?: Int32;
|
||||||
|
@ -24,6 +24,7 @@ export type ReactVideoSourceProperties = {
|
|||||||
uri?: string;
|
uri?: string;
|
||||||
isNetwork?: boolean;
|
isNetwork?: boolean;
|
||||||
isAsset?: boolean;
|
isAsset?: boolean;
|
||||||
|
isLocalAssetFile?: boolean;
|
||||||
shouldCache?: boolean;
|
shouldCache?: boolean;
|
||||||
type?: string;
|
type?: string;
|
||||||
mainVer?: number;
|
mainVer?: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user