Minor cleanup to mediasession extension

- Make units of time clear for seeking
- Remove option to specify supported repeat modes in default
  playback controller. It doesn't seem useful, given we can't
  control what the session is sent.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220464529
This commit is contained in:
olly 2018-11-07 08:09:16 -08:00 committed by Oliver Woodman
parent 0dfd478a20
commit 2d606f26f7
3 changed files with 26 additions and 39 deletions

View File

@ -20,7 +20,6 @@ import android.os.ResultReceiver;
import android.support.v4.media.session.PlaybackStateCompat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.util.RepeatModeUtil;
/**
* A default implementation of {@link MediaSessionConnector.PlaybackController}.
@ -45,32 +44,27 @@ public class DefaultPlaybackController implements MediaSessionConnector.Playback
protected final long rewindIncrementMs;
protected final long fastForwardIncrementMs;
protected final int repeatToggleModes;
/**
* Creates a new instance.
* <p>
* Equivalent to {@code DefaultPlaybackController(DefaultPlaybackController.DEFAULT_REWIND_MS,
* DefaultPlaybackController.DEFAULT_FAST_FORWARD_MS,
* MediaSessionConnector.DEFAULT_REPEAT_TOGGLE_MODES)}.
*
* <p>Equivalent to {@code DefaultPlaybackController(DefaultPlaybackController.DEFAULT_REWIND_MS,
* DefaultPlaybackController.DEFAULT_FAST_FORWARD_MS)}.
*/
public DefaultPlaybackController() {
this(DEFAULT_REWIND_MS, DEFAULT_FAST_FORWARD_MS,
MediaSessionConnector.DEFAULT_REPEAT_TOGGLE_MODES);
this(DEFAULT_REWIND_MS, DEFAULT_FAST_FORWARD_MS);
}
/**
* Creates a new instance with the given fast forward and rewind increments.
* @param rewindIncrementMs The rewind increment in milliseconds. A zero or negative value will
*
* @param rewindIncrementMs The rewind increment in milliseconds. A zero or negative value will
* cause the rewind action to be disabled.
* @param fastForwardIncrementMs The fast forward increment in milliseconds. A zero or negative
* @param repeatToggleModes The available repeatToggleModes.
*/
public DefaultPlaybackController(long rewindIncrementMs, long fastForwardIncrementMs,
@RepeatModeUtil.RepeatToggleModes int repeatToggleModes) {
public DefaultPlaybackController(long rewindIncrementMs, long fastForwardIncrementMs) {
this.rewindIncrementMs = rewindIncrementMs;
this.fastForwardIncrementMs = fastForwardIncrementMs;
this.repeatToggleModes = repeatToggleModes;
}
@Override
@ -101,12 +95,12 @@ public class DefaultPlaybackController implements MediaSessionConnector.Playback
}
@Override
public void onSeekTo(Player player, long position) {
public void onSeekTo(Player player, long positionMs) {
long duration = player.getDuration();
if (duration != C.TIME_UNSET) {
position = Math.min(position, duration);
positionMs = Math.min(positionMs, duration);
}
player.seekTo(Math.max(position, 0));
player.seekTo(Math.max(positionMs, 0));
}
@Override
@ -137,25 +131,21 @@ public class DefaultPlaybackController implements MediaSessionConnector.Playback
}
@Override
public void onSetRepeatMode(Player player, int repeatMode) {
int selectedExoPlayerRepeatMode = player.getRepeatMode();
switch (repeatMode) {
public void onSetRepeatMode(Player player, int mediaSessionRepeatMode) {
int repeatMode;
switch (mediaSessionRepeatMode) {
case PlaybackStateCompat.REPEAT_MODE_ALL:
case PlaybackStateCompat.REPEAT_MODE_GROUP:
if ((repeatToggleModes & RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL) != 0) {
selectedExoPlayerRepeatMode = Player.REPEAT_MODE_ALL;
}
repeatMode = Player.REPEAT_MODE_ALL;
break;
case PlaybackStateCompat.REPEAT_MODE_ONE:
if ((repeatToggleModes & RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE) != 0) {
selectedExoPlayerRepeatMode = Player.REPEAT_MODE_ONE;
}
repeatMode = Player.REPEAT_MODE_ONE;
break;
default:
selectedExoPlayerRepeatMode = Player.REPEAT_MODE_OFF;
repeatMode = Player.REPEAT_MODE_OFF;
break;
}
player.setRepeatMode(selectedExoPlayerRepeatMode);
player.setRepeatMode(repeatMode);
}
// CommandReceiver implementation.

View File

@ -39,7 +39,6 @@ import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ErrorMessageProvider;
import com.google.android.exoplayer2.util.RepeatModeUtil;
import com.google.android.exoplayer2.util.Util;
import java.util.Collections;
import java.util.HashMap;
@ -76,13 +75,6 @@ public final class MediaSessionConnector {
ExoPlayerLibraryInfo.registerModule("goog.exo.mediasession");
}
/**
* The default repeat toggle modes which is the bitmask of {@link
* RepeatModeUtil#REPEAT_TOGGLE_MODE_ONE} and {@link RepeatModeUtil#REPEAT_TOGGLE_MODE_ALL}.
*/
public static final @RepeatModeUtil.RepeatToggleModes int DEFAULT_REPEAT_TOGGLE_MODES =
RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE | RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL;
public static final String EXTRAS_PITCH = "EXO_PITCH";
private static final int BASE_MEDIA_SESSION_FLAGS =
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
@ -167,7 +159,7 @@ public final class MediaSessionConnector {
/** See {@link MediaSessionCompat.Callback#onPause()}. */
void onPause(Player player);
/** See {@link MediaSessionCompat.Callback#onSeekTo(long)}. */
void onSeekTo(Player player, long position);
void onSeekTo(Player player, long positionMs);
/** See {@link MediaSessionCompat.Callback#onFastForward()}. */
void onFastForward(Player player);
/** See {@link MediaSessionCompat.Callback#onRewind()}. */
@ -857,9 +849,9 @@ public final class MediaSessionConnector {
}
@Override
public void onSeekTo(long position) {
public void onSeekTo(long positionMs) {
if (canDispatchToPlaybackController(PlaybackStateCompat.ACTION_SEEK_TO)) {
playbackController.onSeekTo(player, position);
playbackController.onSeekTo(player, positionMs);
}
}

View File

@ -26,6 +26,11 @@ import com.google.android.exoplayer2.util.RepeatModeUtil;
*/
public final class RepeatModeActionProvider implements MediaSessionConnector.CustomActionProvider {
/** The default repeat toggle modes. */
@RepeatModeUtil.RepeatToggleModes
public static final int DEFAULT_REPEAT_TOGGLE_MODES =
RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE | RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL;
private static final String ACTION_REPEAT_MODE = "ACTION_EXO_REPEAT_MODE";
private final Player player;
@ -45,7 +50,7 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
* @param player The player on which to toggle the repeat mode.
*/
public RepeatModeActionProvider(Context context, Player player) {
this(context, player, MediaSessionConnector.DEFAULT_REPEAT_TOGGLE_MODES);
this(context, player, DEFAULT_REPEAT_TOGGLE_MODES);
}
/**