resolving conflicts

This commit is contained in:
Emrah Kaya 2018-06-09 21:30:38 +02:00
parent fefbe801ef
commit 623b562295
2 changed files with 21 additions and 14 deletions

View File

@ -1,10 +1,11 @@
package com.brentvatne.exoplayer; package com.brentvatne.exoplayer;
import android.content.Context; import android.content.Context;
import android.util.ArrayMap; import android.content.ContextWrapper;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableNativeMap; import com.facebook.react.modules.network.CookieJarContainer;
import com.facebook.react.modules.network.ForwardingCookieHandler;
import com.facebook.react.modules.network.OkHttpClientProvider; import com.facebook.react.modules.network.OkHttpClientProvider;
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory; import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
@ -13,8 +14,9 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList; import okhttp3.Cookie;
import java.util.HashMap; import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient;
import java.util.Map; import java.util.Map;
public class DataSourceUtil { public class DataSourceUtil {
@ -48,7 +50,7 @@ public class DataSourceUtil {
DataSourceUtil.rawDataSourceFactory = factory; DataSourceUtil.rawDataSourceFactory = factory;
} }
public static DataSource.Factory getDefaultDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) { public static DataSource.Factory getDefaultDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) {
if (defaultDataSourceFactory == null || (requestHeaders != null && !requestHeaders.isEmpty())) { if (defaultDataSourceFactory == null || (requestHeaders != null && !requestHeaders.isEmpty())) {
defaultDataSourceFactory = buildDataSourceFactory(context, bandwidthMeter, requestHeaders); defaultDataSourceFactory = buildDataSourceFactory(context, bandwidthMeter, requestHeaders);
} }
@ -63,14 +65,18 @@ public class DataSourceUtil {
return new RawResourceDataSourceFactory(context.getApplicationContext()); return new RawResourceDataSourceFactory(context.getApplicationContext());
} }
private static DataSource.Factory buildDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) { private static DataSource.Factory buildDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) {
Context appContext = context.getApplicationContext(); return new DefaultDataSourceFactory(context, bandwidthMeter,
return new DefaultDataSourceFactory(appContext, bandwidthMeter, buildHttpDataSourceFactory(context, bandwidthMeter, requestHeaders));
buildHttpDataSourceFactory(appContext, bandwidthMeter, requestHeaders));
} }
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) { private static HttpDataSource.Factory buildHttpDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) {
OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(OkHttpClientProvider.getOkHttpClient(), getUserAgent(context), bandwidthMeter); OkHttpClient client = OkHttpClientProvider.getOkHttpClient();
CookieJarContainer container = (CookieJarContainer) client.cookieJar();
ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
container.setCookieJar(new JavaNetCookieJar(handler));
OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, getUserAgent(context), bandwidthMeter);
if (requestHeaders != null) if (requestHeaders != null)
okHttpDataSourceFactory.getDefaultRequestProperties().set(requestHeaders); okHttpDataSourceFactory.getDefaultRequestProperties().set(requestHeaders);

View File

@ -104,6 +104,7 @@ class ReactExoplayerView extends FrameLayout implements
private boolean disableFocus; private boolean disableFocus;
private float mProgressUpdateInterval = 250.0f; private float mProgressUpdateInterval = 250.0f;
private boolean playInBackground = false; private boolean playInBackground = false;
private boolean useTextureView = false;
private Map<String, String> requestHeaders; private Map<String, String> requestHeaders;
// \ End props // \ End props
@ -366,7 +367,7 @@ class ReactExoplayerView extends FrameLayout implements
* @return A new DataSource factory. * @return A new DataSource factory.
*/ */
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) { private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
return DataSourceUtil.getDefaultDataSourceFactory(getContext(), useBandwidthMeter ? BANDWIDTH_METER : null, requestHeaders); return DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, useBandwidthMeter ? BANDWIDTH_METER : null, requestHeaders);
} }
// AudioManager.OnAudioFocusChangeListener implementation // AudioManager.OnAudioFocusChangeListener implementation
@ -584,7 +585,7 @@ class ReactExoplayerView extends FrameLayout implements
this.srcUri = uri; this.srcUri = uri;
this.extension = extension; this.extension = extension;
this.requestHeaders = headers; this.requestHeaders = headers;
this.mediaDataSourceFactory = DataSourceUtil.getDefaultDataSourceFactory(getContext(), BANDWIDTH_METER, requestHeaders); this.mediaDataSourceFactory = DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, BANDWIDTH_METER, requestHeaders);
if (!isOriginalSourceNull && !isSourceEqual) { if (!isOriginalSourceNull && !isSourceEqual) {
reloadSource(); reloadSource();