Skip to content

Commit

Permalink
[av][android] upgrade exoplayer to 2.18.1 (#19332)
Browse files Browse the repository at this point in the history
# Why

close ENG-6246

# How

- upgrade exoplayer to 2.18.1
- migrate breaking changes
- kotlinize _packages/expo-av/android/src/main/java/expo/modules/av/player/datasource/CustomHeadersOkHttpDataSourceFactory.java_
- remove _android/expoview/src/main/java/versioned/host/exp/exponent/modules/universal/av/CustomHeadersOkHttpDataSourceFactory.kt_ which is exactly the same to the CustomHeadersOkHttpDataSourceFactory inside expo-av package.

# Test Plan

- android unversioned expo go + NCL Video
  • Loading branch information
Kudo committed Oct 5, 2022
1 parent 550446c commit 26276ba
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 269 deletions.
2 changes: 1 addition & 1 deletion android/expoview/build.gradle
Expand Up @@ -411,7 +411,7 @@ dependencies {

// expo-av
// See explanation in expo-av/build.gradle
api 'com.google.android.exoplayer:extension-okhttp:2.13.3'
api 'com.google.android.exoplayer:extension-okhttp:2.18.1'

// expo-application
api 'com.android.installreferrer:installreferrer:1.0'
Expand Down
Expand Up @@ -5,6 +5,7 @@ import com.facebook.react.modules.network.NetworkingModule
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.TransferListener
import expo.modules.av.player.datasource.CustomHeadersOkHttpDataSourceFactory

class SharedCookiesDataSourceFactory(
reactApplicationContext: ReactContext,
Expand Down
2 changes: 1 addition & 1 deletion android/versioned-abis/expoview-abi45_0_0/build.gradle
Expand Up @@ -191,7 +191,7 @@ dependencies {

// expo-av
// See explanation in expo-av/build.gradle
api 'com.google.android.exoplayer:extension-okhttp:2.13.3'
api 'com.google.android.exoplayer:extension-okhttp:2.18.1'

// expo-application
api 'com.android.installreferrer:installreferrer:1.0'
Expand Down
Expand Up @@ -13,16 +13,16 @@
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.LoadEventInfo;
import com.google.android.exoplayer2.source.MediaLoadData;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
Expand All @@ -37,7 +37,7 @@
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;
import com.google.android.exoplayer2.video.VideoSize;

import java.io.IOException;
import java.util.Map;
Expand All @@ -47,7 +47,7 @@
import abi45_0_0.expo.modules.av.player.datasource.DataSourceFactoryProvider;

class SimpleExoPlayerData extends PlayerData
implements Player.EventListener, MediaSourceEventListener, VideoListener {
implements Player.Listener, MediaSourceEventListener {

private static final String IMPLEMENTATION_NAME = "SimpleExoPlayer";
private static final String TAG = SimpleExoPlayerData.class.getSimpleName();
Expand Down Expand Up @@ -92,7 +92,6 @@ public void load(final Bundle status, final LoadCompletionListener loadCompletio
.build();

mSimpleExoPlayer.addListener(this);
mSimpleExoPlayer.addVideoListener(this);

// Produces DataSource instances through which media data is loaded.
final DataSource.Factory dataSourceFactory = mAVModule.getModuleRegistry()
Expand Down Expand Up @@ -263,7 +262,7 @@ public void updateVolumeMuteAndDuck() {

// endregion

// region ExoPlayer.EventListener
// region Player.Listener

@Override
public void onLoadingChanged(final boolean isLoading) {
Expand All @@ -275,11 +274,6 @@ public void onLoadingChanged(final boolean isLoading) {
public void onPlaybackParametersChanged(PlaybackParameters parameters) {
}

@Override
public void onSeekProcessed() {

}

@Override
public void onRepeatModeChanged(int repeatMode) {
}
Expand Down Expand Up @@ -312,7 +306,7 @@ public void onPlayerStateChanged(final boolean playWhenReady, final int playback
}

@Override
public void onPlayerError(final ExoPlaybackException error) {
public void onPlayerError(PlaybackException error) {
onFatalError(error.getCause());
}

Expand All @@ -325,11 +319,27 @@ public void onPositionDiscontinuity(int reason) {
// Source: https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/Timeline.Period.html
// So I guess it's safe to say that when a period transition happens,
// media file transition happens, so we just finished playing one.
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
callStatusUpdateListenerWithDidJustFinish();
}
}

@Override
public void onVideoSizeChanged(VideoSize videoSize) {
mVideoWidthHeight = new Pair<>(videoSize.width, videoSize.height);
if (mFirstFrameRendered && mVideoSizeUpdateListener != null) {
mVideoSizeUpdateListener.onVideoSizeUpdate(mVideoWidthHeight);
}
}

@Override
public void onRenderedFirstFrame() {
if (!mFirstFrameRendered && mVideoWidthHeight != null && mVideoSizeUpdateListener != null) {
mVideoSizeUpdateListener.onVideoSizeUpdate(mVideoWidthHeight);
}
mFirstFrameRendered = true;
}

// endregion

// region MediaSourceEventListener
Expand Down Expand Up @@ -363,27 +373,6 @@ private void onFatalError(final Throwable error) {

// endregion

// region VideoListener

@Override
public void onVideoSizeChanged(final int width, final int height, final int unAppliedRotationDegrees, final float pixelWidthHeightRatio) {
// TODO other params?
mVideoWidthHeight = new Pair<>(width, height);
if (mFirstFrameRendered && mVideoSizeUpdateListener != null) {
mVideoSizeUpdateListener.onVideoSizeUpdate(mVideoWidthHeight);
}
}

@Override
public void onRenderedFirstFrame() {
if (!mFirstFrameRendered && mVideoWidthHeight != null && mVideoSizeUpdateListener != null) {
mVideoSizeUpdateListener.onVideoSizeUpdate(mVideoWidthHeight);
}
mFirstFrameRendered = true;
}

// endregion

private MediaSource buildMediaSource(@NonNull Uri uri, String overrideExtension, DataSource.Factory factory) {
try {
if (uri.getScheme() == null) {
Expand All @@ -405,7 +394,7 @@ private MediaSource buildMediaSource(@NonNull Uri uri, String overrideExtension,
case C.TYPE_HLS:
return new HlsMediaSource.Factory(factory).createMediaSource(MediaItem.fromUri(uri));
case C.TYPE_OTHER:
return new ExtractorMediaSource.Factory(factory).createMediaSource(MediaItem.fromUri(uri));
return new ProgressiveMediaSource.Factory(factory).createMediaSource(MediaItem.fromUri(uri));
default: {
throw new IllegalStateException("Content of this type is unsupported at the moment. Unsupported type: " + type);
}
Expand Down

This file was deleted.

@@ -1,5 +1,6 @@
package abi46_0_0.host.exp.exponent.modules.universal.av
package abi45_0_0.expo.modules.av.player.datasource

import androidx.collection.ArrayMap
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory
import com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
Expand All @@ -15,16 +16,15 @@ class CustomHeadersOkHttpDataSourceFactory(
) : BaseFactory() {
private val cacheControl: CacheControl? = null

private fun updateRequestProperties(
requestProperties: RequestProperties,
requestHeaders: Map<String, Any>?
) {
private fun updateRequestProperties(requestHeaders: Map<String, Any>?) {
if (requestHeaders != null) {
val requestProperties = ArrayMap<String, String>()
for ((key, value) in requestHeaders) {
if (value is String) {
requestProperties[key] = value
}
}
setDefaultRequestProperties(requestProperties)
}
}

Expand All @@ -33,6 +33,6 @@ class CustomHeadersOkHttpDataSourceFactory(
}

init {
updateRequestProperties(defaultRequestProperties, requestHeaders)
updateRequestProperties(requestHeaders)
}
}
Expand Up @@ -2,6 +2,7 @@ package abi45_0_0.host.exp.exponent.modules.universal.av

import abi45_0_0.com.facebook.react.bridge.ReactContext
import abi45_0_0.com.facebook.react.modules.network.NetworkingModule
import abi45_0_0.expo.modules.av.player.datasource.CustomHeadersOkHttpDataSourceFactory
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.TransferListener
Expand Down
2 changes: 1 addition & 1 deletion android/versioned-abis/expoview-abi46_0_0/build.gradle
Expand Up @@ -181,7 +181,7 @@ dependencies {

// expo-av
// See explanation in expo-av/build.gradle
api 'com.google.android.exoplayer:extension-okhttp:2.13.3'
api 'com.google.android.exoplayer:extension-okhttp:2.18.1'

// expo-application
api 'com.android.installreferrer:installreferrer:1.0'
Expand Down

0 comments on commit 26276ba

Please sign in to comment.