Remove deprecated ControlDispatcher from API surface

PiperOrigin-RevId: 403101980
This commit is contained in:
kimvde 2021-10-14 16:36:45 +01:00 committed by Oliver Woodman
parent 059dfaef7c
commit 746ad2e6aa
14 changed files with 29 additions and 227 deletions

View file

@ -107,6 +107,12 @@
`Player.EVENT_MEDIA_METADATA_CHANGED` for convenient access to
structured metadata, or access the raw static metadata directly from the
`TrackSelection#getFormat()`.
* Remove `setControlDispatcher` from `PlayerWrapper`,
`SessionPlayerConnector`, `MediaSessionConnector`, `PlayerControlView`,
`PlayerNotificationManager`, `PlayerView`, `StyledPlayerControlView`,
`StyledPlayerView` and `LeanbackPlayerAdapter`. Operations can be
customized by using a `ForwardingPlayer`, or when configuring the player
(for example by using `ExoPlayer.Builder.setSeekBackIncrementMs`).
### 2.15.1 (2021-09-20)

View file

@ -29,7 +29,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.ForwardingPlayer;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.DiscontinuityReason;
@ -76,17 +75,6 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
controlDispatcher = new DefaultControlDispatcher();
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to the constructor instead. You can also
* customize some operations when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(@Nullable ControlDispatcher controlDispatcher) {
this.controlDispatcher =
controlDispatcher == null ? new DefaultControlDispatcher() : controlDispatcher;
}
/**
* Sets the optional {@link ErrorMessageProvider}.
*

View file

@ -42,8 +42,6 @@ import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ForwardingPlayer;
import com.google.android.exoplayer2.Player;
@ -152,37 +150,6 @@ public class SessionPlayerConnectorTest {
.isTrue();
}
@Test
@LargeTest
public void play_withCustomControlDispatcher_isSkipped() throws Exception {
if (Looper.myLooper() == null) {
Looper.prepare();
}
ControlDispatcher controlDispatcher =
new DefaultControlDispatcher() {
@Override
public boolean dispatchSetPlayWhenReady(Player player, boolean playWhenReady) {
return false;
}
};
ExoPlayer exoPlayer = null;
SessionPlayerConnector playerConnector = null;
try {
exoPlayer = new ExoPlayer.Builder(context).setLooper(Looper.myLooper()).build();
playerConnector = new SessionPlayerConnector(exoPlayer, new DefaultMediaItemConverter());
playerConnector.setControlDispatcher(controlDispatcher);
assertPlayerResult(playerConnector.play(), RESULT_INFO_SKIPPED);
} finally {
if (playerConnector != null) {
playerConnector.close();
}
if (exoPlayer != null) {
exoPlayer.release();
}
}
}
@Test
@LargeTest
public void play_withForwardingPlayer_isSkipped() throws Exception {

View file

@ -35,7 +35,6 @@ import androidx.media2.common.SessionPlayer;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.ForwardingPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
@ -163,16 +162,6 @@ import java.util.List;
}
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to the constructor instead. You can also
* customize some operations when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
this.controlDispatcher = controlDispatcher;
}
public boolean setMediaItem(androidx.media2.common.MediaItem media2MediaItem) {
return setPlaylist(Collections.singletonList(media2MediaItem), /* metadata= */ null);
}

View file

@ -29,9 +29,7 @@ import androidx.media2.common.FileMediaItem;
import androidx.media2.common.MediaItem;
import androidx.media2.common.MediaMetadata;
import androidx.media2.common.SessionPlayer;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.ForwardingPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log;
@ -113,16 +111,6 @@ public final class SessionPlayerConnector extends SessionPlayer {
playerCommandQueue = new PlayerCommandQueue(this.player, taskHandler);
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to the constructor instead. You can also
* customize some operations when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
player.setControlDispatcher(controlDispatcher);
}
@Override
public ListenableFuture<PlayerResult> play() {
return playerCommandQueue.addCommand(

View file

@ -48,7 +48,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.ForwardingPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
@ -173,21 +172,13 @@ public final class MediaSessionConnector {
* receiver may handle the command, but is not required to do so.
*
* @param player The player connected to the media session.
* @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
* @param command The command name.
* @param extras Optional parameters for the command, may be null.
* @param cb A result receiver to which a result may be sent by the command, may be null.
* @return Whether the receiver handled the command.
*/
boolean onCommand(
Player player,
@Deprecated ControlDispatcher controlDispatcher,
String command,
@Nullable Bundle extras,
@Nullable ResultReceiver cb);
Player player, String command, @Nullable Bundle extras, @Nullable ResultReceiver cb);
}
/** Interface to which playback preparation and play actions are delegated. */
@ -296,32 +287,20 @@ public final class MediaSessionConnector {
* See {@link MediaSessionCompat.Callback#onSkipToPrevious()}.
*
* @param player The player connected to the media session.
* @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
void onSkipToPrevious(Player player, @Deprecated ControlDispatcher controlDispatcher);
void onSkipToPrevious(Player player);
/**
* See {@link MediaSessionCompat.Callback#onSkipToQueueItem(long)}.
*
* @param player The player connected to the media session.
* @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
void onSkipToQueueItem(Player player, @Deprecated ControlDispatcher controlDispatcher, long id);
void onSkipToQueueItem(Player player, long id);
/**
* See {@link MediaSessionCompat.Callback#onSkipToNext()}.
*
* @param player The player connected to the media session.
* @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
void onSkipToNext(Player player, @Deprecated ControlDispatcher controlDispatcher);
void onSkipToNext(Player player);
}
/** Handles media session queue edits. */
@ -374,15 +353,10 @@ public final class MediaSessionConnector {
* See {@link MediaSessionCompat.Callback#onMediaButtonEvent(Intent)}.
*
* @param player The {@link Player}.
* @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
* @param mediaButtonEvent The {@link Intent}.
* @return True if the event was handled, false otherwise.
*/
boolean onMediaButtonEvent(
Player player, @Deprecated ControlDispatcher controlDispatcher, Intent mediaButtonEvent);
boolean onMediaButtonEvent(Player player, Intent mediaButtonEvent);
}
/**
@ -394,18 +368,10 @@ public final class MediaSessionConnector {
* Called when a custom action provided by this provider is sent to the media session.
*
* @param player The player connected to the media session.
* @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
* @param action The name of the action which was sent by a media controller.
* @param extras Optional extras sent by a media controller, may be null.
*/
void onCustomAction(
Player player,
@Deprecated ControlDispatcher controlDispatcher,
String action,
@Nullable Bundle extras);
void onCustomAction(Player player, String action, @Nullable Bundle extras);
/**
* Returns a {@link PlaybackStateCompat.CustomAction} which will be published to the media
@ -559,19 +525,6 @@ public final class MediaSessionConnector {
}
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to {@link #setPlayer(Player)} instead.
* You can also customize some operations when configuring the player (for example by using
* {@code ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
if (this.controlDispatcher != controlDispatcher) {
this.controlDispatcher = controlDispatcher;
invalidateMediaSessionPlaybackState();
}
}
/**
* Sets the {@link MediaButtonEventHandler}. Pass {@code null} if the media button event should be
* handled by {@link MediaSessionCompat.Callback#onMediaButtonEvent(Intent)}.
@ -1317,28 +1270,28 @@ public final class MediaSessionConnector {
@Override
public void onSkipToNext() {
if (canDispatchToQueueNavigator(PlaybackStateCompat.ACTION_SKIP_TO_NEXT)) {
queueNavigator.onSkipToNext(player, controlDispatcher);
queueNavigator.onSkipToNext(player);
}
}
@Override
public void onSkipToPrevious() {
if (canDispatchToQueueNavigator(PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)) {
queueNavigator.onSkipToPrevious(player, controlDispatcher);
queueNavigator.onSkipToPrevious(player);
}
}
@Override
public void onSkipToQueueItem(long id) {
if (canDispatchToQueueNavigator(PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM)) {
queueNavigator.onSkipToQueueItem(player, controlDispatcher, id);
queueNavigator.onSkipToQueueItem(player, id);
}
}
@Override
public void onCustomAction(String action, @Nullable Bundle extras) {
if (player != null && customActionMap.containsKey(action)) {
customActionMap.get(action).onCustomAction(player, controlDispatcher, action, extras);
customActionMap.get(action).onCustomAction(player, action, extras);
invalidateMediaSessionPlaybackState();
}
}
@ -1347,14 +1300,12 @@ public final class MediaSessionConnector {
public void onCommand(String command, @Nullable Bundle extras, @Nullable ResultReceiver cb) {
if (player != null) {
for (int i = 0; i < commandReceivers.size(); i++) {
if (commandReceivers.get(i).onCommand(player, controlDispatcher, command, extras, cb)) {
if (commandReceivers.get(i).onCommand(player, command, extras, cb)) {
return;
}
}
for (int i = 0; i < customCommandReceivers.size(); i++) {
if (customCommandReceivers
.get(i)
.onCommand(player, controlDispatcher, command, extras, cb)) {
if (customCommandReceivers.get(i).onCommand(player, command, extras, cb)) {
return;
}
}
@ -1456,8 +1407,7 @@ public final class MediaSessionConnector {
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
boolean isHandled =
canDispatchMediaButtonEvent()
&& mediaButtonEventHandler.onMediaButtonEvent(
player, controlDispatcher, mediaButtonEvent);
&& mediaButtonEventHandler.onMediaButtonEvent(player, mediaButtonEvent);
return isHandled || super.onMediaButtonEvent(mediaButtonEvent);
}
}

View file

@ -19,7 +19,6 @@ import android.content.Context;
import android.os.Bundle;
import android.support.v4.media.session.PlaybackStateCompat;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.util.RepeatModeUtil;
@ -64,15 +63,11 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
}
@Override
public void onCustomAction(
Player player,
@Deprecated ControlDispatcher controlDispatcher,
String action,
@Nullable Bundle extras) {
public void onCustomAction(Player player, String action, @Nullable Bundle extras) {
int mode = player.getRepeatMode();
int proposedMode = RepeatModeUtil.getNextRepeatMode(mode, repeatToggleModes);
if (mode != proposedMode) {
controlDispatcher.dispatchSetRepeatMode(player, proposedMode);
player.setRepeatMode(proposedMode);
}
}

View file

@ -22,7 +22,6 @@ import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.util.Util;
@ -178,11 +177,7 @@ public final class TimelineQueueEditor
@Override
public boolean onCommand(
Player player,
@Deprecated ControlDispatcher controlDispatcher,
String command,
@Nullable Bundle extras,
@Nullable ResultReceiver cb) {
Player player, String command, @Nullable Bundle extras, @Nullable ResultReceiver cb) {
if (!COMMAND_MOVE_QUEUE_ITEM.equals(command) || extras == null) {
return false;
}

View file

@ -27,7 +27,6 @@ import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.util.Assertions;
@ -144,37 +143,32 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
}
@Override
public void onSkipToPrevious(Player player, @Deprecated ControlDispatcher controlDispatcher) {
controlDispatcher.dispatchPrevious(player);
public void onSkipToPrevious(Player player) {
player.seekToPrevious();
}
@Override
public void onSkipToQueueItem(
Player player, @Deprecated ControlDispatcher controlDispatcher, long id) {
public void onSkipToQueueItem(Player player, long id) {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty() || player.isPlayingAd()) {
return;
}
int windowIndex = (int) id;
if (0 <= windowIndex && windowIndex < timeline.getWindowCount()) {
controlDispatcher.dispatchSeekTo(player, windowIndex, C.TIME_UNSET);
player.seekToDefaultPosition(windowIndex);
}
}
@Override
public void onSkipToNext(Player player, @Deprecated ControlDispatcher controlDispatcher) {
controlDispatcher.dispatchNext(player);
public void onSkipToNext(Player player) {
player.seekToNext();
}
// CommandReceiver implementation.
@Override
public boolean onCommand(
Player player,
@Deprecated ControlDispatcher controlDispatcher,
String command,
@Nullable Bundle extras,
@Nullable ResultReceiver cb) {
Player player, String command, @Nullable Bundle extras, @Nullable ResultReceiver cb) {
return false;
}

View file

@ -52,9 +52,7 @@ import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.ForwardingPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.Events;
import com.google.android.exoplayer2.Player.State;
@ -611,19 +609,6 @@ public class PlayerControlView extends FrameLayout {
this.progressUpdateListener = listener;
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to {@link #setPlayer(Player)} instead.
* You can also customize some operations when configuring the player (for example by using
* {@link ExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
if (this.controlDispatcher != controlDispatcher) {
this.controlDispatcher = controlDispatcher;
updateNavigation();
}
}
/**
* Sets whether the rewind button is shown.
*

View file

@ -54,7 +54,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.ForwardingPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.util.NotificationUtil;
import com.google.android.exoplayer2.util.Util;
@ -816,21 +815,6 @@ public class PlayerNotificationManager {
}
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to {@link #setPlayer(Player)} instead.
* You can also customize some operations when configuring the player (for example by using
* {@code ExoPlayer.Builder.setSeekBackIncrementMs(long)}), or configure whether the rewind
* and fast forward actions should be used with {{@link #setUseRewindAction(boolean)}} and
* {@link #setUseFastForwardAction(boolean)}.
*/
@Deprecated
public final void setControlDispatcher(ControlDispatcher controlDispatcher) {
if (this.controlDispatcher != controlDispatcher) {
this.controlDispatcher = controlDispatcher;
invalidate();
}
}
/**
* Sets whether the next action should be used.
*

View file

@ -46,8 +46,6 @@ import androidx.annotation.Nullable;
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.ForwardingPlayer;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
@ -927,17 +925,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
}
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to {@link #setPlayer(Player)} instead.
* You can also customize some operations when configuring the player (for example by using
* {@code ExoPlayer.Builder.setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
Assertions.checkStateNotNull(controller);
controller.setControlDispatcher(controlDispatcher);
}
/**
* Sets whether the rewind button is shown.
*

View file

@ -831,19 +831,6 @@ public class StyledPlayerControlView extends FrameLayout {
this.progressUpdateListener = listener;
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to {@link #setPlayer(Player)} instead.
* You can also customize some operations when configuring the player (for example by using
* {@code ExoPlayer.Builder.setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
if (this.controlDispatcher != controlDispatcher) {
this.controlDispatcher = controlDispatcher;
updateNavigation();
}
}
/**
* Sets whether the rewind button is shown.
*

View file

@ -47,8 +47,6 @@ import androidx.annotation.Nullable;
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.ForwardingPlayer;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
@ -944,17 +942,6 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
controller.setOnFullScreenModeChangedListener(listener);
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to {@link #setPlayer(Player)} instead.
* You can also customize some operations when configuring the player (for example by using
* {@code ExoPlayer.Builder.setSeekBackIncrementMs(long)}).
*/
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) {
Assertions.checkStateNotNull(controller);
controller.setControlDispatcher(controlDispatcher);
}
/**
* Sets whether the rewind button is shown.
*