Skip to content

Commit

Permalink
feat: upgrade exoplayer to v2.17.1 (TheWidlarzGroup#2498)
Browse files Browse the repository at this point in the history
Describe the changes
Upgrade ExoPlayer to version 2.17.1

Provide an example of how to test the change
Tested with a forked of react-native-video-test

* Update exoplayer to v2.15.1

* feat: upgrade ExoPlayer to version 2.17.1

* chore: update CHANGELOG

* remove ExoPlayerFullscreenVideoActivity

* Fix build issues

* Fix build & runtime issues

Co-authored-by: Eran Hammer <[email protected]>
Co-authored-by: Armands Malejev <[email protected]>
  • Loading branch information
3 people authored Jun 15, 2022
1 parent 33930c8 commit daf5e59
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 217 deletions.
6 changes: 3 additions & 3 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,10 @@ allprojects {
... // Various other settings go here
project.ext {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
compileSdkVersion = 31
buildToolsVersion = "30.0.2"
minSdkVersion = 16
minSdkVersion = 21
targetSdkVersion = 22
}
}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Convert iOS implementation to Swift [#2527](https://github.com/react-native-video/react-native-video/pull/2527)
- Add iOS support for decoding offline sources [#2527](https://github.com/react-native-video/react-native-video/pull/2527)
- Update basic example applications (React Native 0.63.4) [#2527](https://github.com/react-native-video/react-native-video/pull/2527)
- Upgrade ExoPlayer to 2.17.1 [#2498](https://github.com/react-native-video/react-native-video/pull/2498)
- Fix volume reset issue in exoPlayer [#2371](https://github.com/react-native-video/react-native-video/pull/2371)
- Change WindowsTargetPlatformVersion to 10.0 [#2706](https://github.com/react-native-video/react-native-video/pull/2706)
- Fixed Android seeking bug [#2712](https://github.com/react-native-video/react-native-video/pull/2712)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1598,10 +1598,10 @@ allprojects {
... // Various other settings go here
project.ext {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
compileSdkVersion = 31
buildToolsVersion = "30.0.2"
minSdkVersion = 16
minSdkVersion = 21
targetSdkVersion = 22
}
}
Expand Down
10 changes: 5 additions & 5 deletions android-exoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ def safeExtGet(prop, fallback) {
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
compileSdkVersion safeExtGet('compileSdkVersion', 31)
buildToolsVersion safeExtGet('buildToolsVersion', '30.0.2')

compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
minSdkVersion safeExtGet('minSdkVersion', 21)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
Expand All @@ -33,7 +33,7 @@ repositories {

dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation('com.google.android.exoplayer:exoplayer:2.13.3') {
implementation('com.google.android.exoplayer:exoplayer:2.17.1') {
exclude group: 'com.android.support'
}

Expand All @@ -42,7 +42,7 @@ dependencies {
implementation "androidx.core:core:1.1.0"
implementation "androidx.media:media:1.1.0"

implementation('com.google.android.exoplayer:extension-okhttp:2.13.3') {
implementation('com.google.android.exoplayer:extension-okhttp:2.17.1') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
implementation 'com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.facebook.react.modules.network.CookieJarContainer;
import com.facebook.react.modules.network.ForwardingCookieHandler;
import com.facebook.react.modules.network.OkHttpClientProvider;
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory;
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.util.Util;

import okhttp3.Call;
import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient;
import java.util.Map;
Expand Down Expand Up @@ -75,7 +76,7 @@ private static DataSource.Factory buildRawDataSourceFactory(ReactContext context
}

private static DataSource.Factory buildDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) {
return new DefaultDataSourceFactory(context, bandwidthMeter,
return new DefaultDataSource.Factory(context,
buildHttpDataSourceFactory(context, bandwidthMeter, requestHeaders));
}

Expand All @@ -84,10 +85,12 @@ private static HttpDataSource.Factory buildHttpDataSourceFactory(ReactContext co
CookieJarContainer container = (CookieJarContainer) client.cookieJar();
ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
container.setCookieJar(new JavaNetCookieJar(handler));
OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, getUserAgent(context), bandwidthMeter);
OkHttpDataSource.Factory okHttpDataSourceFactory = new OkHttpDataSource.Factory((Call.Factory) client)
.setUserAgent(getUserAgent(context))
.setTransferListener(bandwidthMeter);

if (requestHeaders != null)
okHttpDataSourceFactory.getDefaultRequestProperties().set(requestHeaders);
okHttpDataSourceFactory.setDefaultRequestProperties(requestHeaders);

return okHttpDataSourceFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
import android.widget.FrameLayout;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.video.VideoListener;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.TracksInfo;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.exoplayer2.video.VideoSize;

import java.util.List;

Expand All @@ -36,7 +34,7 @@ public final class ExoPlayerView extends FrameLayout {
private final SubtitleView subtitleLayout;
private final AspectRatioFrameLayout layout;
private final ComponentListener componentListener;
private SimpleExoPlayer player;
private ExoPlayer player;
private Context context;
private ViewGroup.LayoutParams layoutParams;

Expand Down Expand Up @@ -131,29 +129,25 @@ private void updateShutterViewVisibility() {
}

/**
* Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#addTextOutput} and
* {@link SimpleExoPlayer#addVideoListener} method of the player will be called and previous
* Set the {@link ExoPlayer} to use. The {@link ExoPlayer#addListener} method of the
* player will be called and previous
* assignments are overridden.
*
* @param player The {@link SimpleExoPlayer} to use.
* @param player The {@link ExoPlayer} to use.
*/
public void setPlayer(SimpleExoPlayer player) {
public void setPlayer(ExoPlayer player) {
if (this.player == player) {
return;
}
if (this.player != null) {
this.player.removeTextOutput(componentListener);
this.player.removeVideoListener(componentListener);
this.player.removeListener(componentListener);
clearVideoView();
}
this.player = player;
shutterView.setVisibility(this.hideShutterView ? View.INVISIBLE : View.VISIBLE);
if (player != null) {
setVideoView();
player.addVideoListener(componentListener);
player.addListener(componentListener);
player.addTextOutput(componentListener);
}
}

Expand Down Expand Up @@ -230,8 +224,7 @@ public void invalidateAspectRatio() {
layout.invalidateAspectRatio();
}

private final class ComponentListener implements VideoListener,
TextOutput, ExoPlayer.EventListener {
private final class ComponentListener implements Player.Listener {

// TextRenderer.Output implementation

Expand All @@ -240,12 +233,12 @@ public void onCues(List<Cue> cues) {
subtitleLayout.onCues(cues);
}

// SimpleExoPlayer.VideoListener implementation
// ExoPlayer.VideoListener implementation

@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
public void onVideoSizeChanged(VideoSize videoSize) {
boolean isInitialRatio = layout.getAspectRatio() == 0;
layout.setAspectRatio(height == 0 ? 1 : (width * pixelWidthHeightRatio) / height);
layout.setAspectRatio(videoSize.height == 0 ? 1 : (videoSize.width * videoSize.pixelWidthHeightRatio) / videoSize.height);

// React native workaround for measuring and layout on initial load.
if (isInitialRatio) {
Expand All @@ -261,43 +254,43 @@ public void onRenderedFirstFrame() {
// ExoPlayer.EventListener implementation

@Override
public void onLoadingChanged(boolean isLoading) {
public void onIsLoadingChanged(boolean isLoading) {
// Do nothing.
}

@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
public void onPlaybackStateChanged(int playbackState) {
// Do nothing.
}

@Override
public void onPlayerError(ExoPlaybackException e) {
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
// Do nothing.
}

@Override
public void onPositionDiscontinuity(int reason) {
public void onPlayerError(PlaybackException e) {
// Do nothing.
}

@Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) {
// Do nothing.
}

@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
updateForCurrentTrackSelections();
public void onTimelineChanged(Timeline timeline, int reason) {
// Do nothing.
}

@Override
public void onPlaybackParametersChanged(PlaybackParameters params) {
// Do nothing
public void onTracksInfoChanged(TracksInfo tracksInfo) {
updateForCurrentTrackSelections();
}

@Override
public void onSeekProcessed() {
// Do nothing.
public void onPlaybackParametersChanged(PlaybackParameters params) {
// Do nothing
}

@Override
Expand Down
Loading

0 comments on commit daf5e59

Please sign in to comment.