diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f586a3ee..cc6c0b8eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Reverted the JS fullscreening for Android. [#2013](https://github.com/react-native-community/react-native-video/pull/2013) - Set iOS request headers without needing to edit RCTVideo.m. [#2014](https://github.com/react-native-community/react-native-video/pull/2014) - Fix exoplayer aspect ratio update on source changes [#2053](https://github.com/react-native-community/react-native-video/pull/2053) +- Added `cookiePolicy` property for ExoPlayer CookieManager [#2082](https://github.com/react-native-community/react-native-video/pull/2082) ### Version 5.1.0-alpha5 diff --git a/README.md b/README.md index 00fc79321c..8273e993cc 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,7 @@ var styles = StyleSheet.create({ * [hideShutterView](#hideshutterview) * [id](#id) * [ignoreSilentSwitch](#ignoresilentswitch) +* [cookiePolicy](#cookiepolicy) * [maxBitRate](#maxbitrate) * [minLoadRetryCount](#minLoadRetryCount) * [mixWithOthers](#mixWithOthers) @@ -513,6 +514,14 @@ Controls the iOS silent switch behavior Platforms: iOS +#### cookiePolicy +Changes the android cookie policy +* **"original" (default)** - Sets the CookiePolicy as ACCEPT_ORIGINAL_SERVER +* **"all"** - Sets the CookiePolicy as ACCEPT_ALL +* **"none"** - Sets the CookiePolicy as ACCEPT_NONE + +Platforms: Android ExoPlayer + #### maxBitRate Sets the desired limit, in bits per second, of network bandwidth consumption when multiple video streams are available for a playlist. diff --git a/Video.js b/Video.js index 450a77969f..26193fcae0 100644 --- a/Video.js +++ b/Video.js @@ -436,6 +436,7 @@ Video.propTypes = { preferredForwardBufferDuration: PropTypes.number, playWhenInactive: PropTypes.bool, ignoreSilentSwitch: PropTypes.oneOf(['ignore', 'obey']), + cookiePolicy: PropTypes.oneOf(['original', 'all', 'none']), reportBandwidth: PropTypes.bool, disableFocus: PropTypes.bool, controls: PropTypes.bool, diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 4e6fea586d..fd7a36a524 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -141,6 +141,7 @@ class ReactExoplayerView extends FrameLayout implements private boolean playInBackground = false; private Map requestHeaders; private boolean mReportBandwidth = false; + private String mCookiePolicy = "original"; private boolean controls; // \ End props @@ -204,6 +205,7 @@ private void createViews() { clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { + DEFAULT_COOKIE_MANAGER.setCookiePolicy(this.getCookiePolicy()); CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } @@ -444,6 +446,18 @@ public void run() { }, 1); } + private CookiePolicy getCookiePolicy() { + switch (mCookiePolicy) { + case "all": + return CookiePolicy.ACCEPT_ALL; + case "none": + return CookiePolicy.ACCEPT_NONE; + case "original": + default: + return CookiePolicy.ACCEPT_ORIGINAL_SERVER; + } + } + private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); @@ -966,6 +980,12 @@ public void setReportBandwidth(boolean reportBandwidth) { mReportBandwidth = reportBandwidth; } + public void setCookiePolicy(String cookiePolicy) { + mCookiePolicy = cookiePolicy; + DEFAULT_COOKIE_MANAGER.setCookiePolicy(this.getCookiePolicy()); + CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); + } + public void setRawSrc(final Uri uri, final String extension) { if (uri != null) { boolean isOriginalSourceNull = srcUri == null; diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index cf50fdaecd..0602deb6bb 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -47,6 +47,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager