From f7c4fd491bb373478d855e4f9fbc5b85ae0863bc Mon Sep 17 00:00:00 2001 From: olly Date: Thu, 29 Apr 2021 19:55:47 +0100 Subject: [PATCH] Remove deprecated PlaybackPreparer PiperOrigin-RevId: 371170769 --- RELEASENOTES.md | 9 ++++++++ .../ext/leanback/LeanbackPlayerAdapter.java | 22 +----------------- .../exoplayer2/ui/PlayerControlView.java | 22 +----------------- .../ui/PlayerNotificationManager.java | 23 +------------------ .../android/exoplayer2/ui/PlayerView.java | 16 ------------- .../ui/StyledPlayerControlView.java | 22 +----------------- .../exoplayer2/ui/StyledPlayerView.java | 17 -------------- 7 files changed, 13 insertions(+), 118 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 7bc6b2c54e..7a04923ed8 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -108,6 +108,15 @@ * Remove `CastPlayer` specific playlist manipulation methods. Use `setMediaItems`, `addMediaItems`, `removeMediaItem` and `moveMediaItem` instead. + * Remove `PlaybackPreparer`. UI components that previously had + `setPlaybackPreparer` methods will now call `Player.prepare` by default. + If this behavior is sufficient, use of `PlaybackPreparer` can be removed + from application code without replacement. For custom preparation logic, + replace calls to `setPlaybackPreparer` with calls to + `setControlDispatcher` on the same components, passing a + `ControlDispatcher` that implements custom preparation logic in + `dispatchPrepare`. Extend `DefaultControlDispatcher` to avoid having to + implement the other `ControlDispatcher` methods. * DRM: * Only dispatch DRM session acquire and release events once per period when playing content that uses the same encryption keys for both audio & diff --git a/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java b/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java index f2fc3279b8..2214bc2488 100644 --- a/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java +++ b/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java @@ -30,7 +30,6 @@ import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlayerLibraryInfo; -import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player.DiscontinuityReason; import com.google.android.exoplayer2.Player.TimelineChangeReason; @@ -51,7 +50,6 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab private final PlayerListener playerListener; private final int updatePeriodMs; - @Nullable private PlaybackPreparer playbackPreparer; private ControlDispatcher controlDispatcher; @Nullable private ErrorMessageProvider errorMessageProvider; @Nullable private SurfaceHolderGlueHost surfaceHolderGlueHost; @@ -76,20 +74,6 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab controlDispatcher = new DefaultControlDispatcher(); } - /** - * @deprecated Use {@link #setControlDispatcher(ControlDispatcher)} instead. The adapter calls - * {@link ControlDispatcher#dispatchPrepare(Player)} instead of {@link - * PlaybackPreparer#preparePlayback()}. The {@link DefaultControlDispatcher} that the adapter - * uses by default, calls {@link Player#prepare()}. If you wish to customize this behaviour, - * you can provide a custom implementation of {@link - * ControlDispatcher#dispatchPrepare(Player)}. - */ - @SuppressWarnings("deprecation") - @Deprecated - public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { - this.playbackPreparer = playbackPreparer; - } - /** * Sets the {@link ControlDispatcher}. * @@ -168,11 +152,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab @Override public void play() { if (player.getPlaybackState() == Player.STATE_IDLE) { - if (playbackPreparer != null) { - playbackPreparer.preparePlayback(); - } else { - controlDispatcher.dispatchPrepare(player); - } + controlDispatcher.dispatchPrepare(player); } else if (player.getPlaybackState() == Player.STATE_ENDED) { controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java index 1499aa556a..d0420452d9 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java @@ -47,7 +47,6 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.ExoPlayerLibraryInfo; -import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player.Events; import com.google.android.exoplayer2.Player.State; @@ -329,7 +328,6 @@ public class PlayerControlView extends FrameLayout { @Nullable private Player player; private com.google.android.exoplayer2.ControlDispatcher controlDispatcher; @Nullable private ProgressUpdateListener progressUpdateListener; - @Nullable private PlaybackPreparer playbackPreparer; private boolean isAttachedToWindow; private boolean showMultiWindowTimeBar; @@ -616,20 +614,6 @@ public class PlayerControlView extends FrameLayout { this.progressUpdateListener = listener; } - /** - * @deprecated Use {@link #setControlDispatcher(ControlDispatcher)} instead. The view calls {@link - * ControlDispatcher#dispatchPrepare(Player)} instead of {@link - * PlaybackPreparer#preparePlayback()}. The {@link DefaultControlDispatcher} that the view - * uses by default, calls {@link Player#prepare()}. If you wish to customize this behaviour, - * you can provide a custom implementation of {@link - * ControlDispatcher#dispatchPrepare(Player)}. - */ - @SuppressWarnings("deprecation") - @Deprecated - public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { - this.playbackPreparer = playbackPreparer; - } - /** * Sets the {@link com.google.android.exoplayer2.ControlDispatcher}. * @@ -1273,11 +1257,7 @@ public class PlayerControlView extends FrameLayout { private void dispatchPlay(Player player) { @State int state = player.getPlaybackState(); if (state == Player.STATE_IDLE) { - if (playbackPreparer != null) { - playbackPreparer.preparePlayback(); - } else { - controlDispatcher.dispatchPrepare(player); - } + controlDispatcher.dispatchPrepare(player); } else if (state == Player.STATE_ENDED) { seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java index 3139cd451d..5956073542 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java @@ -52,7 +52,6 @@ import androidx.media.app.NotificationCompat.MediaStyle; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.DefaultControlDispatcher; -import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.util.NotificationUtil; @@ -641,7 +640,6 @@ public class PlayerNotificationManager { @Nullable private NotificationCompat.Builder builder; @Nullable private List builderActions; @Nullable private Player player; - @Nullable private PlaybackPreparer playbackPreparer; private ControlDispatcher controlDispatcher; private boolean isNotificationStarted; private int currentNotificationTag; @@ -916,21 +914,6 @@ public class PlayerNotificationManager { } } - /** - * @deprecated Use {@link #setControlDispatcher(ControlDispatcher)} instead. The manager calls - * {@link ControlDispatcher#dispatchPrepare(Player)} instead of {@link - * PlaybackPreparer#preparePlayback()}. The {@link DefaultControlDispatcher} that this manager - * uses by default, calls {@link Player#prepare()}. If you wish to intercept or customize this - * behaviour, you can provide a custom implementation of {@link - * ControlDispatcher#dispatchPrepare(Player)} and pass it to {@link - * #setControlDispatcher(ControlDispatcher)}. - */ - @SuppressWarnings("deprecation") - @Deprecated - public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { - this.playbackPreparer = playbackPreparer; - } - /** * Sets the {@link ControlDispatcher}. * @@ -1639,11 +1622,7 @@ public class PlayerNotificationManager { String action = intent.getAction(); if (ACTION_PLAY.equals(action)) { if (player.getPlaybackState() == Player.STATE_IDLE) { - if (playbackPreparer != null) { - playbackPreparer.preparePlayback(); - } else { - controlDispatcher.dispatchPrepare(player); - } + controlDispatcher.dispatchPrepare(player); } else if (player.getPlaybackState() == Player.STATE_ENDED) { controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index f7b7f6b157..4d26df9d28 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -49,7 +49,6 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player.DiscontinuityReason; import com.google.android.exoplayer2.Timeline; @@ -913,21 +912,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider { } } - /** - * @deprecated Use {@link #setControlDispatcher(ControlDispatcher)} instead. The view calls {@link - * ControlDispatcher#dispatchPrepare(Player)} instead of {@link - * PlaybackPreparer#preparePlayback()}. The {@link DefaultControlDispatcher} that the view - * uses by default, calls {@link Player#prepare()}. If you wish to customize this behaviour, - * you can provide a custom implementation of {@link - * ControlDispatcher#dispatchPrepare(Player)}. - */ - @SuppressWarnings("deprecation") - @Deprecated - public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { - Assertions.checkStateNotNull(controller); - controller.setPlaybackPreparer(playbackPreparer); - } - /** * Sets the {@link ControlDispatcher}. * diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java index c2e7446e8a..62aeb2bfe4 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java @@ -57,7 +57,6 @@ import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.Format; -import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player.Events; import com.google.android.exoplayer2.Player.State; @@ -417,7 +416,6 @@ public class StyledPlayerControlView extends FrameLayout { @Nullable private Player player; private ControlDispatcher controlDispatcher; @Nullable private ProgressUpdateListener progressUpdateListener; - @Nullable private PlaybackPreparer playbackPreparer; @Nullable private OnFullScreenModeChangedListener onFullScreenModeChangedListener; private boolean isFullScreen; @@ -847,20 +845,6 @@ public class StyledPlayerControlView extends FrameLayout { this.progressUpdateListener = listener; } - /** - * @deprecated Use {@link #setControlDispatcher(ControlDispatcher)} instead. The view calls {@link - * ControlDispatcher#dispatchPrepare(Player)} instead of {@link - * PlaybackPreparer#preparePlayback()}. The {@link DefaultControlDispatcher} that the view - * uses by default, calls {@link Player#prepare()}. If you wish to customize this behaviour, - * you can provide a custom implementation of {@link - * ControlDispatcher#dispatchPrepare(Player)}. - */ - @SuppressWarnings("deprecation") - @Deprecated - public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { - this.playbackPreparer = playbackPreparer; - } - /** * Sets the {@link ControlDispatcher}. * @@ -1702,11 +1686,7 @@ public class StyledPlayerControlView extends FrameLayout { private void dispatchPlay(Player player) { @State int state = player.getPlaybackState(); if (state == Player.STATE_IDLE) { - if (playbackPreparer != null) { - playbackPreparer.preparePlayback(); - } else { - controlDispatcher.dispatchPrepare(player); - } + controlDispatcher.dispatchPrepare(player); } else if (state == Player.STATE_ENDED) { seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java index 01248c1bf5..043a4b8920 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java @@ -48,9 +48,7 @@ import androidx.annotation.RequiresApi; import androidx.core.content.ContextCompat; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ControlDispatcher; -import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player.DiscontinuityReason; import com.google.android.exoplayer2.Timeline; @@ -930,21 +928,6 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { controller.setOnFullScreenModeChangedListener(listener); } - /** - * @deprecated Use {@link #setControlDispatcher(ControlDispatcher)} instead. The view calls {@link - * ControlDispatcher#dispatchPrepare(Player)} instead of {@link - * PlaybackPreparer#preparePlayback()}. The {@link DefaultControlDispatcher} that the view - * uses by default, calls {@link Player#prepare()}. If you wish to customize this behaviour, - * you can provide a custom implementation of {@link - * ControlDispatcher#dispatchPrepare(Player)}. - */ - @SuppressWarnings("deprecation") - @Deprecated - public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { - Assertions.checkStateNotNull(controller); - controller.setPlaybackPreparer(playbackPreparer); - } - /** * Sets the {@link ControlDispatcher}. *