mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
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:
parent
0dfd478a20
commit
2d606f26f7
@ -20,7 +20,6 @@ import android.os.ResultReceiver;
|
|||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.util.RepeatModeUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A default implementation of {@link MediaSessionConnector.PlaybackController}.
|
* A default implementation of {@link MediaSessionConnector.PlaybackController}.
|
||||||
@ -45,32 +44,27 @@ public class DefaultPlaybackController implements MediaSessionConnector.Playback
|
|||||||
|
|
||||||
protected final long rewindIncrementMs;
|
protected final long rewindIncrementMs;
|
||||||
protected final long fastForwardIncrementMs;
|
protected final long fastForwardIncrementMs;
|
||||||
protected final int repeatToggleModes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
* <p>
|
*
|
||||||
* Equivalent to {@code DefaultPlaybackController(DefaultPlaybackController.DEFAULT_REWIND_MS,
|
* <p>Equivalent to {@code DefaultPlaybackController(DefaultPlaybackController.DEFAULT_REWIND_MS,
|
||||||
* DefaultPlaybackController.DEFAULT_FAST_FORWARD_MS,
|
* DefaultPlaybackController.DEFAULT_FAST_FORWARD_MS)}.
|
||||||
* MediaSessionConnector.DEFAULT_REPEAT_TOGGLE_MODES)}.
|
|
||||||
*/
|
*/
|
||||||
public DefaultPlaybackController() {
|
public DefaultPlaybackController() {
|
||||||
this(DEFAULT_REWIND_MS, DEFAULT_FAST_FORWARD_MS,
|
this(DEFAULT_REWIND_MS, DEFAULT_FAST_FORWARD_MS);
|
||||||
MediaSessionConnector.DEFAULT_REPEAT_TOGGLE_MODES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the given fast forward and rewind increments.
|
* 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.
|
* cause the rewind action to be disabled.
|
||||||
* @param fastForwardIncrementMs The fast forward increment in milliseconds. A zero or negative
|
* @param fastForwardIncrementMs The fast forward increment in milliseconds. A zero or negative
|
||||||
* @param repeatToggleModes The available repeatToggleModes.
|
|
||||||
*/
|
*/
|
||||||
public DefaultPlaybackController(long rewindIncrementMs, long fastForwardIncrementMs,
|
public DefaultPlaybackController(long rewindIncrementMs, long fastForwardIncrementMs) {
|
||||||
@RepeatModeUtil.RepeatToggleModes int repeatToggleModes) {
|
|
||||||
this.rewindIncrementMs = rewindIncrementMs;
|
this.rewindIncrementMs = rewindIncrementMs;
|
||||||
this.fastForwardIncrementMs = fastForwardIncrementMs;
|
this.fastForwardIncrementMs = fastForwardIncrementMs;
|
||||||
this.repeatToggleModes = repeatToggleModes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,12 +95,12 @@ public class DefaultPlaybackController implements MediaSessionConnector.Playback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSeekTo(Player player, long position) {
|
public void onSeekTo(Player player, long positionMs) {
|
||||||
long duration = player.getDuration();
|
long duration = player.getDuration();
|
||||||
if (duration != C.TIME_UNSET) {
|
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
|
@Override
|
||||||
@ -137,25 +131,21 @@ public class DefaultPlaybackController implements MediaSessionConnector.Playback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetRepeatMode(Player player, int repeatMode) {
|
public void onSetRepeatMode(Player player, int mediaSessionRepeatMode) {
|
||||||
int selectedExoPlayerRepeatMode = player.getRepeatMode();
|
int repeatMode;
|
||||||
switch (repeatMode) {
|
switch (mediaSessionRepeatMode) {
|
||||||
case PlaybackStateCompat.REPEAT_MODE_ALL:
|
case PlaybackStateCompat.REPEAT_MODE_ALL:
|
||||||
case PlaybackStateCompat.REPEAT_MODE_GROUP:
|
case PlaybackStateCompat.REPEAT_MODE_GROUP:
|
||||||
if ((repeatToggleModes & RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL) != 0) {
|
repeatMode = Player.REPEAT_MODE_ALL;
|
||||||
selectedExoPlayerRepeatMode = Player.REPEAT_MODE_ALL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PlaybackStateCompat.REPEAT_MODE_ONE:
|
case PlaybackStateCompat.REPEAT_MODE_ONE:
|
||||||
if ((repeatToggleModes & RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE) != 0) {
|
repeatMode = Player.REPEAT_MODE_ONE;
|
||||||
selectedExoPlayerRepeatMode = Player.REPEAT_MODE_ONE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
selectedExoPlayerRepeatMode = Player.REPEAT_MODE_OFF;
|
repeatMode = Player.REPEAT_MODE_OFF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
player.setRepeatMode(selectedExoPlayerRepeatMode);
|
player.setRepeatMode(repeatMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandReceiver implementation.
|
// CommandReceiver implementation.
|
||||||
|
@ -39,7 +39,6 @@ import com.google.android.exoplayer2.Player;
|
|||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.ErrorMessageProvider;
|
import com.google.android.exoplayer2.util.ErrorMessageProvider;
|
||||||
import com.google.android.exoplayer2.util.RepeatModeUtil;
|
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -76,13 +75,6 @@ public final class MediaSessionConnector {
|
|||||||
ExoPlayerLibraryInfo.registerModule("goog.exo.mediasession");
|
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";
|
public static final String EXTRAS_PITCH = "EXO_PITCH";
|
||||||
private static final int BASE_MEDIA_SESSION_FLAGS =
|
private static final int BASE_MEDIA_SESSION_FLAGS =
|
||||||
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
|
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
|
||||||
@ -167,7 +159,7 @@ public final class MediaSessionConnector {
|
|||||||
/** See {@link MediaSessionCompat.Callback#onPause()}. */
|
/** See {@link MediaSessionCompat.Callback#onPause()}. */
|
||||||
void onPause(Player player);
|
void onPause(Player player);
|
||||||
/** See {@link MediaSessionCompat.Callback#onSeekTo(long)}. */
|
/** See {@link MediaSessionCompat.Callback#onSeekTo(long)}. */
|
||||||
void onSeekTo(Player player, long position);
|
void onSeekTo(Player player, long positionMs);
|
||||||
/** See {@link MediaSessionCompat.Callback#onFastForward()}. */
|
/** See {@link MediaSessionCompat.Callback#onFastForward()}. */
|
||||||
void onFastForward(Player player);
|
void onFastForward(Player player);
|
||||||
/** See {@link MediaSessionCompat.Callback#onRewind()}. */
|
/** See {@link MediaSessionCompat.Callback#onRewind()}. */
|
||||||
@ -857,9 +849,9 @@ public final class MediaSessionConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSeekTo(long position) {
|
public void onSeekTo(long positionMs) {
|
||||||
if (canDispatchToPlaybackController(PlaybackStateCompat.ACTION_SEEK_TO)) {
|
if (canDispatchToPlaybackController(PlaybackStateCompat.ACTION_SEEK_TO)) {
|
||||||
playbackController.onSeekTo(player, position);
|
playbackController.onSeekTo(player, positionMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,11 @@ import com.google.android.exoplayer2.util.RepeatModeUtil;
|
|||||||
*/
|
*/
|
||||||
public final class RepeatModeActionProvider implements MediaSessionConnector.CustomActionProvider {
|
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 static final String ACTION_REPEAT_MODE = "ACTION_EXO_REPEAT_MODE";
|
||||||
|
|
||||||
private final Player player;
|
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.
|
* @param player The player on which to toggle the repeat mode.
|
||||||
*/
|
*/
|
||||||
public RepeatModeActionProvider(Context context, Player player) {
|
public RepeatModeActionProvider(Context context, Player player) {
|
||||||
this(context, player, MediaSessionConnector.DEFAULT_REPEAT_TOGGLE_MODES);
|
this(context, player, DEFAULT_REPEAT_TOGGLE_MODES);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user