Skip to content

Commit

Permalink
update ExoPlayer to r2.15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
warren-bank committed Oct 6, 2021
1 parent 7b6a4aa commit f2b8750
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#### origin for pre-built native extension binaries:

* [Just Player](https://github.com/moneytoo/Player/tree/v0.45/app/libs)
- release: 0.45 (using ExoPlayer 2.14.2)
* [Just Player](https://github.com/moneytoo/Player/tree/v0.65/app/libs)
- release: 0.65 (using ExoPlayer 2.15.1)
- extensions:
* [_av1_](https://github.com/moneytoo/Player/raw/v0.45/app/libs/extension-av1-release.aar)
* [_ffmpeg_](https://github.com/moneytoo/Player/raw/v0.45/app/libs/extension-ffmpeg-release.aar)
* [_av1_](https://github.com/moneytoo/Player/raw/v0.65/app/libs/extension-av1-release.aar)
* [_ffmpeg_](https://github.com/moneytoo/Player/raw/v0.65/app/libs/extension-ffmpeg-release.aar)
- ABIs:
* armeabi-v7a
* arm64-v8a
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.github.warren_bank.exoplayer_airplay_receiver.exoplayer2.customizations.MyLoadErrorHandlingPolicy;
import com.github.warren_bank.exoplayer_airplay_receiver.exoplayer2.customizations.MyRenderersFactory;
import com.github.warren_bank.exoplayer_airplay_receiver.exoplayer2.customizations.TextSynchronizer;
import com.github.warren_bank.exoplayer_airplay_receiver.utils.ExoPlayerUtils;
import com.github.warren_bank.exoplayer_airplay_receiver.utils.ExternalStorageUtils;
import com.github.warren_bank.exoplayer_airplay_receiver.utils.MediaSourceUtils;
import com.github.warren_bank.exoplayer_airplay_receiver.utils.MediaTypeUtils;
Expand All @@ -25,9 +24,9 @@

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
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.Player.DiscontinuityReason;
Expand Down Expand Up @@ -692,8 +691,8 @@ public void AirPlay_queue(
public void AirPlay_next() {
if (exoPlayer == null) return;

if (exoPlayer.hasNext()) {
exoPlayer.next();
if (exoPlayer.hasNextWindow()) {
exoPlayer.seekToNextWindow();
}
}

Expand All @@ -703,8 +702,8 @@ public void AirPlay_next() {
public void AirPlay_previous() {
if (exoPlayer == null) return;

if (exoPlayer.hasPrevious()) {
exoPlayer.previous();
if (exoPlayer.hasPreviousWindow()) {
exoPlayer.seekToPreviousWindow();
}
}

Expand Down Expand Up @@ -930,7 +929,11 @@ private void release_exoPlayer() {
}
}

// ===========================================================================
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/common/src/main/java/com/google/android/exoplayer2/Player.java#L83
// ===========================================================================
// Player.EventListener implementation.
// ===========================================================================

@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
Expand All @@ -944,22 +947,50 @@ public void onPositionDiscontinuity(@DiscontinuityReason int reason) {

@Override
public void onTimelineChanged(
Timeline timeline, @Nullable Object manifest, @TimelineChangeReason int reason
Timeline timeline, @TimelineChangeReason int reason
){
updateCurrentItemIndex();
}

@Override
public void onPlayerError(ExoPlaybackException error) {
if (exoPlayer == null)
return;
if (error.type != ExoPlaybackException.TYPE_SOURCE)
public void onPlayerError(PlaybackException error) {
if ((error == null) || (exoPlayer == null))
return;

if (ExoPlayerUtils.isBehindLiveWindow(error) || ExoPlayerUtils.isHttpDataSource(error))
retry();
else
exoPlayer.next();
switch(error.errorCode) {
case PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW :
case PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE :
case PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED :
case PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT :
case PlaybackException.ERROR_CODE_DRM_SYSTEM_ERROR :
case PlaybackException.ERROR_CODE_DRM_DEVICE_REVOKED :
case PlaybackException.ERROR_CODE_DRM_LICENSE_EXPIRED : {
retry();
break;
}
case PlaybackException.ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE :
case PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS :
case PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND :
case PlaybackException.ERROR_CODE_IO_NO_PERMISSION :
case PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED :
case PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED :
case PlaybackException.ERROR_CODE_PARSING_MANIFEST_MALFORMED :
case PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED :
case PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED :
case PlaybackException.ERROR_CODE_DECODER_INIT_FAILED :
case PlaybackException.ERROR_CODE_DECODER_QUERY_FAILED :
case PlaybackException.ERROR_CODE_DECODING_FAILED :
case PlaybackException.ERROR_CODE_DECODING_FORMAT_EXCEEDS_CAPABILITIES :
case PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED :
case PlaybackException.ERROR_CODE_AUDIO_TRACK_INIT_FAILED :
case PlaybackException.ERROR_CODE_DRM_SCHEME_UNSUPPORTED :
case PlaybackException.ERROR_CODE_DRM_PROVISIONING_FAILED :
case PlaybackException.ERROR_CODE_DRM_CONTENT_ERROR :
case PlaybackException.ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED : {
exoPlayer.seekToNextWindow();
break;
}
}
}

// Internal methods.
Expand All @@ -974,8 +1005,8 @@ private void init() {
private void retry() {
if (exoPlayer == null) return;

exoPlayer.retry();
exoPlayer.seekToDefaultPosition();
exoPlayer.retry();
}

private void truncateQueue(int count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;

import java.io.IOException;

Expand Down Expand Up @@ -37,15 +38,27 @@ public MyLoadErrorHandlingPolicy(int retryCount, long offlineRetryDelayMs) {
this.offlineRetryDelayMs = offlineRetryDelayMs;
}

// ===========================================================================
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicy.java#L108
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoadErrorHandlingPolicy.java#L70
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/core/src/main/java/com/google/android/exoplayer2/source/LoadEventInfo.java
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/core/src/main/java/com/google/android/exoplayer2/source/MediaLoadData.java
// ===========================================================================

@Override
public long getRetryDelayMsFor(int dataType, long loadDurationMs, IOException exception, int errorCount) {
public long getRetryDelayMsFor(LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo) {
int dataType = loadErrorInfo.mediaLoadData.dataType;
long loadDurationMs = loadErrorInfo.loadEventInfo.loadDurationMs;
IOException exception = loadErrorInfo.exception;
int errorCount = loadErrorInfo.errorCount;

Log.e(TAG, "getRetryDelayMsFor [" + errorCount + "@" + loadDurationMs + "]", exception);

isOffline = (exception instanceof HttpDataSourceException);

return (isOffline)
? offlineRetryDelayMs
: super.getRetryDelayMsFor(dataType, loadDurationMs, exception, errorCount)
: super.getRetryDelayMsFor(loadErrorInfo)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
public class MyPlayerNotificationManager extends PlayerNotificationManager {
private PlayerManager playerManager;

public void setPlayerManager(PlayerManager pm) {
playerManager = pm;
}

// ===========================================================================
// https://github.com/google/ExoPlayer/blob/r2.11.3/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L989
// https://github.com/google/ExoPlayer/blob/r2.11.3/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L1037
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L1171
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L1215
// ===========================================================================
// * startOrUpdateNotification(...)
// - calls createNotification(...)
Expand All @@ -40,52 +44,129 @@ protected NotificationCompat.Builder createNotification(
@Nullable Bitmap largeIcon
) {
int currentItemIndex = player.getCurrentWindowIndex();
VideoSource sample = playerManager.getItem(currentItemIndex);
VideoSource sample = (playerManager == null) ? null : playerManager.getItem(currentItemIndex);

return (sample == null)
? null
: super.createNotification(player, builder, ongoing, largeIcon);
}

// ===========================================================================
// https://github.com/google/ExoPlayer/blob/r2.11.3/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L447
// https://github.com/google/ExoPlayer/blob/r2.11.3/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L524
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L308
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L351
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L557
// ===========================================================================
// * createWithNotificationChannel(...)
// - static method that performs a task before calling the class constructor
// * class Builder{...}
// ===========================================================================

public static MyPlayerNotificationManager createWithNotificationChannel(
PlayerManager playerManager,
public static class Builder extends PlayerNotificationManager.Builder {
public Builder(Context context, int notificationId, String channelId) {
super(context, notificationId, channelId);
}

@Override
public MyPlayerNotificationManager build() {
if (channelNameResourceId != 0) {
NotificationUtil.createNotificationChannel(
context,
channelId,
channelNameResourceId,
channelDescriptionResourceId,
channelImportance);
}

return new MyPlayerNotificationManager(
context,
channelId,
notificationId,
mediaDescriptionAdapter,
notificationListener,
customActionReceiver,
smallIconResourceId,
playActionIconResourceId,
pauseActionIconResourceId,
stopActionIconResourceId,
rewindActionIconResourceId,
fastForwardActionIconResourceId,
previousActionIconResourceId,
nextActionIconResourceId,
groupKey
);
}
}

// ===========================================================================
// https://github.com/google/ExoPlayer/blob/r2.15.1/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L710
// ===========================================================================
// * PlayerNotificationManager(...)
// - constructor
// ===========================================================================

protected MyPlayerNotificationManager(
Context context,
String channelId,
@StringRes int channelName,
@StringRes int channelDescription,
int notificationId,
MediaDescriptionAdapter mediaDescriptionAdapter
MediaDescriptionAdapter mediaDescriptionAdapter,
@Nullable NotificationListener notificationListener,
@Nullable CustomActionReceiver customActionReceiver,
int smallIconResourceId,
int playActionIconResourceId,
int pauseActionIconResourceId,
int stopActionIconResourceId,
int rewindActionIconResourceId,
int fastForwardActionIconResourceId,
int previousActionIconResourceId,
int nextActionIconResourceId,
@Nullable String groupKey
) {
NotificationUtil.createNotificationChannel(context, channelId, channelName, channelDescription, NotificationUtil.IMPORTANCE_LOW);

return new MyPlayerNotificationManager(playerManager, context, channelId, notificationId, mediaDescriptionAdapter);
super(
context,
channelId,
notificationId,
mediaDescriptionAdapter,
notificationListener,
customActionReceiver,
smallIconResourceId,
playActionIconResourceId,
pauseActionIconResourceId,
stopActionIconResourceId,
rewindActionIconResourceId,
fastForwardActionIconResourceId,
previousActionIconResourceId,
nextActionIconResourceId,
groupKey
);
}

public MyPlayerNotificationManager(
// ===========================================================================
// convenience method
// ===========================================================================

public static MyPlayerNotificationManager createWithNotificationChannel(
PlayerManager playerManager,
Context context,
String channelId,
@StringRes int channelName,
@StringRes int channelDescription,
int notificationId,
MediaDescriptionAdapter mediaDescriptionAdapter
) {
super(
MyPlayerNotificationManager.Builder builder = new MyPlayerNotificationManager.Builder(
context,
channelId,
notificationId,
mediaDescriptionAdapter,
/* notificationListener= */ null,
/* customActionReceiver= */ null
channelId
);

this.playerManager = playerManager;
builder
.setChannelNameResourceId(channelName)
.setChannelDescriptionResourceId(channelDescription)
.setMediaDescriptionAdapter(mediaDescriptionAdapter)
;

MyPlayerNotificationManager myPlayerNotificationManager = builder.build();
myPlayerNotificationManager.setPlayerManager(playerManager);

return myPlayerNotificationManager;
}

}

This file was deleted.

2 changes: 1 addition & 1 deletion android-studio-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0' // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
classpath 'com.android.tools.build:gradle:3.3.3' // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
classpath 'com.google.android.gms:strict-version-matcher-plugin:1.1.0' // https://mvnrepository.com/artifact/com.google.android.gms/strict-version-matcher-plugin
}
}
Expand Down
Loading

0 comments on commit f2b8750

Please sign in to comment.