Upgrade to ExoPlayer 2.8.2

This commit is contained in:
Hampton Maxwell 2018-08-07 23:10:03 -07:00
parent f0ee821225
commit 40cafdcb2e
3 changed files with 42 additions and 27 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.8.2' compile('com.google.android.exoplayer:exoplayer:2.8.2') {
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') { 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,32 +803,30 @@ 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);
} }
} }
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) {