Merge pull request #1170 from react-native-community/chore/exoplayer-2.8.2-upgrade

[WIP] Update ExoPlayer to version 2.8.2
This commit is contained in:
Hampton Maxwell 2018-08-07 23:12:09 -07:00 committed by GitHub
commit 8dbc2554dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 28 deletions

View File

@ -5,7 +5,10 @@ A `<Video>` component for react-native, as seen in
Requires react-native >= 0.40.0, for RN support of 0.19.0 - 0.39.0 please use a pre 1.0 version. Requires react-native >= 0.40.0, for RN support of 0.19.0 - 0.39.0 please use a pre 1.0 version.
### Version 3.0 breaking changes ### Version 4.0.0 breaking changes
Version 4.0 now requires Android SDK 26 or higher to use ExoPlayer. This is the default version as of React Native 0.56 and will be required by Google for all apps in October 2018.
### Version 3.0.0 breaking changes
Version 3.0 features a number of changes to existing behavior. See [Updating](#updating) for changes. Version 3.0 features a number of changes to existing behavior. See [Updating](#updating) for changes.
## TOC ## TOC

View File

@ -19,9 +19,18 @@ android {
dependencies { dependencies {
//noinspection GradleDynamicVersion //noinspection GradleDynamicVersion
provided "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" provided "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
compile 'com.google.android.exoplayer:exoplayer:2.7.3' compile('com.google.android.exoplayer:exoplayer:2.8.2') {
compile('com.google.android.exoplayer:extension-okhttp:2.7.3') { exclude group: 'com.android.support'
}
// All support libs must use the same version
compile "com.android.support:support-annotations:${safeExtGet('supportLibVersion', '+')}"
compile "com.android.support:support-compat:${safeExtGet('supportLibVersion', '+')}"
compile "com.android.support:support-media-compat:${safeExtGet('supportLibVersion', '+')}"
compile('com.google.android.exoplayer:extension-okhttp:2.8.2') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp' exclude group: 'com.squareup.okhttp3', module: 'okhttp'
} }
compile 'com.squareup.okhttp3:okhttp:3.9.1' compile 'com.squareup.okhttp3:okhttp:3.11.0'
} }

View File

@ -98,7 +98,7 @@ class ReactExoplayerView extends FrameLayout implements
private DataSource.Factory mediaDataSourceFactory; private DataSource.Factory mediaDataSourceFactory;
private SimpleExoPlayer player; private SimpleExoPlayer player;
private MappingTrackSelector trackSelector; private DefaultTrackSelector trackSelector;
private boolean playerNeedsSource; private boolean playerNeedsSource;
private int resumeWindow; private int resumeWindow;
@ -533,12 +533,12 @@ class ReactExoplayerView extends FrameLayout implements
TrackGroupArray groups = info.getTrackGroups(index); TrackGroupArray groups = info.getTrackGroups(index);
for (int i = 0; i < groups.length; ++i) { for (int i = 0; i < groups.length; ++i) {
Format format = groups.get(i).getFormat(0); Format format = groups.get(i).getFormat(0);
WritableMap textTrack = Arguments.createMap(); WritableMap audioTrack = Arguments.createMap();
textTrack.putInt("index", i); audioTrack.putInt("index", i);
textTrack.putString("title", format.id != null ? format.id : ""); audioTrack.putString("title", format.id != null ? format.id : "");
textTrack.putString("type", format.sampleMimeType); audioTrack.putString("type", format.sampleMimeType);
textTrack.putString("language", format.language != null ? format.language : ""); audioTrack.putString("language", format.language != null ? format.language : "");
audioTracks.pushMap(textTrack); audioTracks.pushMap(audioTrack);
} }
return audioTracks; return audioTracks;
} }
@ -774,8 +774,13 @@ class ReactExoplayerView extends FrameLayout implements
type = "default"; type = "default";
} }
DefaultTrackSelector.Parameters disableParameters = trackSelector.getParameters()
.buildUpon()
.setRendererDisabled(rendererIndex, true)
.build();
if (type.equals("disabled")) { if (type.equals("disabled")) {
trackSelector.setSelectionOverride(rendererIndex, groups, null); trackSelector.setParameters(disableParameters);
return; return;
} else if (type.equals("language")) { } else if (type.equals("language")) {
for (int i = 0; i < groups.length; ++i) { for (int i = 0; i < groups.length; ++i) {
@ -798,17 +803,12 @@ class ReactExoplayerView extends FrameLayout implements
trackIndex = value.asInt(); trackIndex = value.asInt();
} }
} else { // default } else { // default
if (rendererIndex == C.TRACK_TYPE_TEXT) { // Use system settings if possible if (rendererIndex == C.TRACK_TYPE_TEXT && Util.SDK_INT > 18 && groups.length > 0) {
int sdk = android.os.Build.VERSION.SDK_INT; // Use system settings if possible
if (sdk > 18 && groups.length > 0) { CaptioningManager captioningManager
CaptioningManager captioningManager = (CaptioningManager)themedReactContext.getSystemService(Context.CAPTIONING_SERVICE);
= (CaptioningManager)themedReactContext.getSystemService(Context.CAPTIONING_SERVICE); if (captioningManager != null && captioningManager.isEnabled()) {
if (captioningManager != null && captioningManager.isEnabled()) { trackIndex = getTrackIndexForDefaultLocale(groups);
trackIndex = getTrackIndexForDefaultLocale(groups);
}
} else {
trackSelector.setSelectionOverride(rendererIndex, groups, null);
return;
} }
} else if (rendererIndex == C.TRACK_TYPE_AUDIO) { } else if (rendererIndex == C.TRACK_TYPE_AUDIO) {
trackIndex = getTrackIndexForDefaultLocale(groups); trackIndex = getTrackIndexForDefaultLocale(groups);
@ -816,14 +816,17 @@ class ReactExoplayerView extends FrameLayout implements
} }
if (trackIndex == C.INDEX_UNSET) { if (trackIndex == C.INDEX_UNSET) {
trackSelector.clearSelectionOverrides(trackIndex); trackSelector.setParameters(disableParameters);
return; return;
} }
MappingTrackSelector.SelectionOverride override DefaultTrackSelector.Parameters selectionParameters = trackSelector.getParameters()
= new MappingTrackSelector.SelectionOverride( .buildUpon()
new FixedTrackSelection.Factory(), trackIndex, 0); .setRendererDisabled(rendererIndex, false)
trackSelector.setSelectionOverride(rendererIndex, groups, override); .setSelectionOverride(rendererIndex, groups,
new DefaultTrackSelector.SelectionOverride(trackIndex, 0))
.build();
trackSelector.setParameters(selectionParameters);
} }
private int getTrackIndexForDefaultLocale(TrackGroupArray groups) { private int getTrackIndexForDefaultLocale(TrackGroupArray groups) {