fix(android): android cache header (#3832)

* fix: android cache header
This commit is contained in:
lovegaoshi
2024-05-28 00:29:21 -07:00
committed by GitHub
parent 5c29b48747
commit c2a14240ad
3 changed files with 18 additions and 16 deletions

View File

@@ -215,7 +215,7 @@ public class ReactExoplayerView extends FrameLayout implements
private boolean selectTrackWhenReady = false;
private Handler mainHandler;
private Runnable mainRunnable;
private DataSource.Factory cacheDataSourceFactory;
private boolean useCache = false;
private ControlsConfig controlsConfig = new ControlsConfig();
// Props from React
@@ -709,8 +709,8 @@ public class ReactExoplayerView extends FrameLayout implements
.setAdErrorListener(this)
.build();
DefaultMediaSourceFactory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory);
if (cacheDataSourceFactory != null) {
mediaSourceFactory.setDataSourceFactory(cacheDataSourceFactory);
if (useCache) {
mediaSourceFactory.setDataSourceFactory(RNVSimpleCache.INSTANCE.getCacheFactory(buildHttpDataSourceFactory(true)));
}
if (adsLoader != null) {
@@ -1016,13 +1016,13 @@ public class ReactExoplayerView extends FrameLayout implements
throw new IllegalStateException("cannot open input file" + srcUri);
}
} else if ("file".equals(srcUri.getScheme()) ||
cacheDataSourceFactory == null) {
!useCache) {
mediaSourceFactory = new ProgressiveMediaSource.Factory(
mediaDataSourceFactory
);
} else {
mediaSourceFactory = new ProgressiveMediaSource.Factory(
cacheDataSourceFactory
RNVSimpleCache.INSTANCE.getCacheFactory(buildHttpDataSourceFactory(true))
);
}
@@ -2241,12 +2241,11 @@ public class ReactExoplayerView extends FrameLayout implements
if (bufferConfig.getCacheSize() > 0) {
RNVSimpleCache.INSTANCE.setSimpleCache(
this.getContext(),
bufferConfig.getCacheSize(),
buildHttpDataSourceFactory(false)
bufferConfig.getCacheSize()
);
cacheDataSourceFactory = RNVSimpleCache.INSTANCE.getCacheDataSourceFactory();
useCache = true;
} else {
cacheDataSourceFactory = null;
useCache = false;
}
releasePlayer();
initializePlayer();