Skip to content

Commit

Permalink
experimental http cache implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jul 25, 2018
1 parent fcd87b8 commit 0e1c7c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions android-exoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.danikula:videocache:2.7.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.content.Context;
import android.content.ContextWrapper;
import android.net.Uri;

import com.danikula.videocache.HttpProxyCacheServer;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.network.CookieJarContainer;
import com.facebook.react.modules.network.ForwardingCookieHandler;
Expand All @@ -27,6 +29,7 @@ private DataSourceUtil() {

private static DataSource.Factory rawDataSourceFactory = null;
private static DataSource.Factory defaultDataSourceFactory = null;
private static HttpProxyCacheServer proxy = null;
private static String userAgent = null;

public static void setUserAgent(String userAgent) {
Expand All @@ -47,7 +50,7 @@ public static DataSource.Factory getRawDataSourceFactory(ReactContext context) {
return rawDataSourceFactory;
}

public static void setRawDataSourceFactory(DataSource.Factory factory) {
public static void setRawDataSourceFactory(DataSource .Factory factory) {
DataSourceUtil.rawDataSourceFactory = factory;
}

Expand Down Expand Up @@ -84,4 +87,14 @@ private static HttpDataSource.Factory buildHttpDataSourceFactory(ReactContext co

return okHttpDataSourceFactory;
}

public static Uri getCacheUri(Uri uri, Context context) {
if (proxy == null) {
proxy = new HttpProxyCacheServer.Builder(context)
.maxCacheSize(1024 * 1024 * 512)
.maxCacheFilesCount(20)
.build();
}
return Uri.parse(proxy.getProxyUrl(uri.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public void setSrc(final Uri uri, final String extension, Map<String, String> he
boolean isOriginalSourceNull = srcUri == null;
boolean isSourceEqual = uri.equals(srcUri);

this.srcUri = uri;
this.srcUri = DataSourceUtil.getCacheUri(uri, themedReactContext);
this.extension = extension;
this.requestHeaders = headers;
this.mediaDataSourceFactory = DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, BANDWIDTH_METER, this.requestHeaders);
Expand Down

0 comments on commit 0e1c7c2

Please sign in to comment.