Deprecate ControlDispatcher in MediaSessionConnector

PiperOrigin-RevId: 386227630
This commit is contained in:
kimvde 2021-07-22 14:46:44 +01:00 committed by kim-vde
parent 13ff72d869
commit b33496aeae
5 changed files with 54 additions and 29 deletions

View File

@ -118,6 +118,11 @@
* RTSP: * RTSP:
* Use standard RTSP header names. * Use standard RTSP header names.
([#9182](https://github.com/google/ExoPlayer/issues/9182)). ([#9182](https://github.com/google/ExoPlayer/issues/9182)).
* MediaSession extension:
* Deprecate `setControlDispatcher` in `MediaSessionConnector`. The
`ControlDispatcher` parameter has also been deprecated in all
`MediaSessionConnector` listener methods.
### 2.14.2 (2021-07-20) ### 2.14.2 (2021-07-20)

View File

@ -48,6 +48,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.ForwardingPlayer;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
@ -169,12 +170,13 @@ public final class MediaSessionConnector {
public interface CommandReceiver { public interface CommandReceiver {
/** /**
* See {@link MediaSessionCompat.Callback#onCommand(String, Bundle, ResultReceiver)}. The * See {@link MediaSessionCompat.Callback#onCommand(String, Bundle, ResultReceiver)}. The
* receiver may handle the command, but is not required to do so. Changes to the player should * receiver may handle the command, but is not required to do so.
* be made via the {@link ControlDispatcher}.
* *
* @param player The player connected to the media session. * @param player The player connected to the media session.
* @param controlDispatcher A {@link ControlDispatcher} that should be used for dispatching * @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* changes to the player. * can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
* @param command The command name. * @param command The command name.
* @param extras Optional parameters for the command, may be null. * @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. * @param cb A result receiver to which a result may be sent by the command, may be null.
@ -182,7 +184,7 @@ public final class MediaSessionConnector {
*/ */
boolean onCommand( boolean onCommand(
Player player, Player player,
ControlDispatcher controlDispatcher, @Deprecated ControlDispatcher controlDispatcher,
String command, String command,
@Nullable Bundle extras, @Nullable Bundle extras,
@Nullable ResultReceiver cb); @Nullable ResultReceiver cb);
@ -294,26 +296,32 @@ public final class MediaSessionConnector {
* See {@link MediaSessionCompat.Callback#onSkipToPrevious()}. * See {@link MediaSessionCompat.Callback#onSkipToPrevious()}.
* *
* @param player The player connected to the media session. * @param player The player connected to the media session.
* @param controlDispatcher A {@link ControlDispatcher} that should be used for dispatching * @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* changes to the player. * can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/ */
void onSkipToPrevious(Player player, ControlDispatcher controlDispatcher); void onSkipToPrevious(Player player, @Deprecated ControlDispatcher controlDispatcher);
/** /**
* See {@link MediaSessionCompat.Callback#onSkipToQueueItem(long)}. * See {@link MediaSessionCompat.Callback#onSkipToQueueItem(long)}.
* *
* @param player The player connected to the media session. * @param player The player connected to the media session.
* @param controlDispatcher A {@link ControlDispatcher} that should be used for dispatching * @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* changes to the player. * can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/ */
void onSkipToQueueItem(Player player, ControlDispatcher controlDispatcher, long id); void onSkipToQueueItem(Player player, @Deprecated ControlDispatcher controlDispatcher, long id);
/** /**
* See {@link MediaSessionCompat.Callback#onSkipToNext()}. * See {@link MediaSessionCompat.Callback#onSkipToNext()}.
* *
* @param player The player connected to the media session. * @param player The player connected to the media session.
* @param controlDispatcher A {@link ControlDispatcher} that should be used for dispatching * @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* changes to the player. * can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/ */
void onSkipToNext(Player player, ControlDispatcher controlDispatcher); void onSkipToNext(Player player, @Deprecated ControlDispatcher controlDispatcher);
} }
/** Handles media session queue edits. */ /** Handles media session queue edits. */
@ -366,13 +374,15 @@ public final class MediaSessionConnector {
* See {@link MediaSessionCompat.Callback#onMediaButtonEvent(Intent)}. * See {@link MediaSessionCompat.Callback#onMediaButtonEvent(Intent)}.
* *
* @param player The {@link Player}. * @param player The {@link Player}.
* @param controlDispatcher A {@link ControlDispatcher} that should be used for dispatching * @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* changes to the player. * can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
* @param mediaButtonEvent The {@link Intent}. * @param mediaButtonEvent The {@link Intent}.
* @return True if the event was handled, false otherwise. * @return True if the event was handled, false otherwise.
*/ */
boolean onMediaButtonEvent( boolean onMediaButtonEvent(
Player player, ControlDispatcher controlDispatcher, Intent mediaButtonEvent); Player player, @Deprecated ControlDispatcher controlDispatcher, Intent mediaButtonEvent);
} }
/** /**
@ -384,13 +394,18 @@ public final class MediaSessionConnector {
* Called when a custom action provided by this provider is sent to the media session. * 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 player The player connected to the media session.
* @param controlDispatcher A {@link ControlDispatcher} that should be used for dispatching * @param controlDispatcher This parameter is deprecated. Use {@code player} instead. Operations
* changes to the player. * can be customized by passing a {@link ForwardingPlayer} to {@link #setPlayer(Player)}, or
* when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
* @param action The name of the action which was sent by a media controller. * @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. * @param extras Optional extras sent by a media controller, may be null.
*/ */
void onCustomAction( void onCustomAction(
Player player, ControlDispatcher controlDispatcher, String action, @Nullable Bundle extras); Player player,
@Deprecated ControlDispatcher controlDispatcher,
String action,
@Nullable Bundle extras);
/** /**
* Returns a {@link PlaybackStateCompat.CustomAction} which will be published to the media * Returns a {@link PlaybackStateCompat.CustomAction} which will be published to the media
@ -545,10 +560,11 @@ public final class MediaSessionConnector {
} }
/** /**
* Sets the {@link ControlDispatcher}. * @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
* @param controlDispatcher The {@link ControlDispatcher}. * {@code SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/ */
@Deprecated
public void setControlDispatcher(ControlDispatcher controlDispatcher) { public void setControlDispatcher(ControlDispatcher controlDispatcher) {
if (this.controlDispatcher != controlDispatcher) { if (this.controlDispatcher != controlDispatcher) {
this.controlDispatcher = controlDispatcher; this.controlDispatcher = controlDispatcher;

View File

@ -65,7 +65,10 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
@Override @Override
public void onCustomAction( public void onCustomAction(
Player player, ControlDispatcher controlDispatcher, String action, @Nullable Bundle extras) { Player player,
@Deprecated ControlDispatcher controlDispatcher,
String action,
@Nullable Bundle extras) {
int mode = player.getRepeatMode(); int mode = player.getRepeatMode();
int proposedMode = RepeatModeUtil.getNextRepeatMode(mode, repeatToggleModes); int proposedMode = RepeatModeUtil.getNextRepeatMode(mode, repeatToggleModes);
if (mode != proposedMode) { if (mode != proposedMode) {

View File

@ -179,7 +179,7 @@ public final class TimelineQueueEditor
@Override @Override
public boolean onCommand( public boolean onCommand(
Player player, Player player,
ControlDispatcher controlDispatcher, @Deprecated ControlDispatcher controlDispatcher,
String command, String command,
@Nullable Bundle extras, @Nullable Bundle extras,
@Nullable ResultReceiver cb) { @Nullable ResultReceiver cb) {

View File

@ -144,12 +144,13 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
} }
@Override @Override
public void onSkipToPrevious(Player player, ControlDispatcher controlDispatcher) { public void onSkipToPrevious(Player player, @Deprecated ControlDispatcher controlDispatcher) {
controlDispatcher.dispatchPrevious(player); controlDispatcher.dispatchPrevious(player);
} }
@Override @Override
public void onSkipToQueueItem(Player player, ControlDispatcher controlDispatcher, long id) { public void onSkipToQueueItem(
Player player, @Deprecated ControlDispatcher controlDispatcher, long id) {
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty() || player.isPlayingAd()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return; return;
@ -161,7 +162,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
} }
@Override @Override
public void onSkipToNext(Player player, ControlDispatcher controlDispatcher) { public void onSkipToNext(Player player, @Deprecated ControlDispatcher controlDispatcher) {
controlDispatcher.dispatchNext(player); controlDispatcher.dispatchNext(player);
} }
@ -170,7 +171,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
@Override @Override
public boolean onCommand( public boolean onCommand(
Player player, Player player,
ControlDispatcher controlDispatcher, @Deprecated ControlDispatcher controlDispatcher,
String command, String command,
@Nullable Bundle extras, @Nullable Bundle extras,
@Nullable ResultReceiver cb) { @Nullable ResultReceiver cb) {