Allow fast forward and rewind actions in compact view

PiperOrigin-RevId: 377107132
This commit is contained in:
bachinger 2021-06-02 19:38:14 +01:00
parent d515e2c1f0
commit 46687fecb1
2 changed files with 80 additions and 7 deletions

View File

@ -66,6 +66,9 @@
* PlayerNotificationManager: * PlayerNotificationManager:
* Add `PendingIntent.FLAG_IMMUTABLE` flag to BroadcastReceiver to support * Add `PendingIntent.FLAG_IMMUTABLE` flag to BroadcastReceiver to support
Android 12. Android 12.
* Add `setUseFastForwardActionInCompactView(boolean)` and
`setUseRewindActionInCompactView(boolean)` to make it possible to show
seek actions in compact view mode.
* DRM: * DRM:
* Don't restore offline keys before releasing them. In OEMCrypto v16+ keys * Don't restore offline keys before releasing them. In OEMCrypto v16+ keys
must be released without restoring them first. must be released without restoring them first.

View File

@ -91,12 +91,24 @@ import java.util.Map;
* <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)} * <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)}
* <li>Default: {@link DefaultControlDispatcher#DEFAULT_REWIND_MS} (5000) * <li>Default: {@link DefaultControlDispatcher#DEFAULT_REWIND_MS} (5000)
* </ul> * </ul>
* <li><b>{@code useRewindActionInCompactView}</b> - Sets whether the rewind action should be
* shown in compact view mode.
* <ul>
* <li>Corresponding setter: {@link #setUseRewindActionInCompactView(boolean)}
* <li>Default: {@code false}
* </ul>
* <li><b>{@code fastForwardIncrementMs}</b> - Sets the fast forward increment. If set to zero the * <li><b>{@code fastForwardIncrementMs}</b> - Sets the fast forward increment. If set to zero the
* fast forward action is not used. * fast forward action is not used.
* <ul> * <ul>
* <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)} * <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)}
* <li>Default: {@link DefaultControlDispatcher#DEFAULT_FAST_FORWARD_MS} (15000) * <li>Default: {@link DefaultControlDispatcher#DEFAULT_FAST_FORWARD_MS} (15000)
* </ul> * </ul>
* <li><b>{@code useFastForwardActionInCompactView}</b> - Sets whether the fast forward action
* should be shown in compact view mode.
* <ul>
* <li>Corresponding setter: {@link #setUseFastForwardActionInCompactView(boolean)}
* <li>Default: {@code false}
* </ul>
* <li><b>{@code usePreviousAction}</b> - Whether the previous action is used. * <li><b>{@code usePreviousAction}</b> - Whether the previous action is used.
* <ul> * <ul>
* <li>Corresponding setter: {@link #setUsePreviousAction(boolean)} * <li>Corresponding setter: {@link #setUsePreviousAction(boolean)}
@ -647,6 +659,8 @@ public class PlayerNotificationManager {
private boolean useNextAction; private boolean useNextAction;
private boolean usePreviousActionInCompactView; private boolean usePreviousActionInCompactView;
private boolean useNextActionInCompactView; private boolean useNextActionInCompactView;
private boolean useRewindActionInCompactView;
private boolean useFastForwardActionInCompactView;
private boolean usePlayPauseActions; private boolean usePlayPauseActions;
private boolean useStopAction; private boolean useStopAction;
private int badgeIconType; private int badgeIconType;
@ -808,11 +822,17 @@ public class PlayerNotificationManager {
* also be used in compact view. Has no effect if {@link #setUseNextAction useNextAction} is * also be used in compact view. Has no effect if {@link #setUseNextAction useNextAction} is
* {@code false}. * {@code false}.
* *
* <p>If set to {@code true}, {@link #setUseFastForwardActionInCompactView(boolean)
* setUseFastForwardActionInCompactView} is set to false.
*
* @param useNextActionInCompactView Whether to use the next action in compact view. * @param useNextActionInCompactView Whether to use the next action in compact view.
*/ */
public void setUseNextActionInCompactView(boolean useNextActionInCompactView) { public void setUseNextActionInCompactView(boolean useNextActionInCompactView) {
if (this.useNextActionInCompactView != useNextActionInCompactView) { if (this.useNextActionInCompactView != useNextActionInCompactView) {
this.useNextActionInCompactView = useNextActionInCompactView; this.useNextActionInCompactView = useNextActionInCompactView;
if (useNextActionInCompactView) {
useFastForwardActionInCompactView = false;
}
invalidate(); invalidate();
} }
} }
@ -822,11 +842,56 @@ public class PlayerNotificationManager {
* action should also be used in compact view. Has no effect if {@link #setUsePreviousAction * action should also be used in compact view. Has no effect if {@link #setUsePreviousAction
* usePreviousAction} is {@code false}. * usePreviousAction} is {@code false}.
* *
* <p>If set to {@code true}, {@link #setUseRewindActionInCompactView(boolean)
* setUseRewindActionInCompactView} is set to false.
*
* @param usePreviousActionInCompactView Whether to use the previous action in compact view. * @param usePreviousActionInCompactView Whether to use the previous action in compact view.
*/ */
public void setUsePreviousActionInCompactView(boolean usePreviousActionInCompactView) { public void setUsePreviousActionInCompactView(boolean usePreviousActionInCompactView) {
if (this.usePreviousActionInCompactView != usePreviousActionInCompactView) { if (this.usePreviousActionInCompactView != usePreviousActionInCompactView) {
this.usePreviousActionInCompactView = usePreviousActionInCompactView; this.usePreviousActionInCompactView = usePreviousActionInCompactView;
if (usePreviousActionInCompactView) {
useRewindActionInCompactView = false;
}
invalidate();
}
}
/**
* Sets whether the fast forward action should also be used in compact view. Has no effect if
* {@link #ACTION_FAST_FORWARD} is not enabled, for instance if the media is not seekable.
*
* <p>If set to {@code true}, {@link #setUseNextActionInCompactView(boolean)
* setUseNextActionInCompactView} is set to false.
*
* @param useFastForwardActionInCompactView Whether to use the fast forward action in compact
* view.
*/
public void setUseFastForwardActionInCompactView(boolean useFastForwardActionInCompactView) {
if (this.useFastForwardActionInCompactView != useFastForwardActionInCompactView) {
this.useFastForwardActionInCompactView = useFastForwardActionInCompactView;
if (useFastForwardActionInCompactView) {
useNextActionInCompactView = false;
}
invalidate();
}
}
/**
* Sets whether the rewind action should also be used in compact view. Has no effect if {@link
* #ACTION_REWIND} is not enabled, for instance if the media is not seekable.
*
* <p>If set to {@code true}, {@link #setUsePreviousActionInCompactView(boolean)
* setUsePreviousActionInCompactView} is set to false.
*
* @param useRewindActionInCompactView Whether to use the rewind action in compact view.
*/
public void setUseRewindActionInCompactView(boolean useRewindActionInCompactView) {
if (this.useRewindActionInCompactView != useRewindActionInCompactView) {
this.useRewindActionInCompactView = useRewindActionInCompactView;
if (useRewindActionInCompactView) {
usePreviousActionInCompactView = false;
}
invalidate(); invalidate();
} }
} }
@ -1255,14 +1320,19 @@ public class PlayerNotificationManager {
protected int[] getActionIndicesForCompactView(List<String> actionNames, Player player) { protected int[] getActionIndicesForCompactView(List<String> actionNames, Player player) {
int pauseActionIndex = actionNames.indexOf(ACTION_PAUSE); int pauseActionIndex = actionNames.indexOf(ACTION_PAUSE);
int playActionIndex = actionNames.indexOf(ACTION_PLAY); int playActionIndex = actionNames.indexOf(ACTION_PLAY);
int previousActionIndex = int leftSideActionIndex =
usePreviousActionInCompactView ? actionNames.indexOf(ACTION_PREVIOUS) : -1; usePreviousActionInCompactView
int nextActionIndex = useNextActionInCompactView ? actionNames.indexOf(ACTION_NEXT) : -1; ? actionNames.indexOf(ACTION_PREVIOUS)
: (useRewindActionInCompactView ? actionNames.indexOf(ACTION_REWIND) : -1);
int rightSideActionIndex =
useNextActionInCompactView
? actionNames.indexOf(ACTION_NEXT)
: (useFastForwardActionInCompactView ? actionNames.indexOf(ACTION_FAST_FORWARD) : -1);
int[] actionIndices = new int[3]; int[] actionIndices = new int[3];
int actionCounter = 0; int actionCounter = 0;
if (previousActionIndex != -1) { if (leftSideActionIndex != -1) {
actionIndices[actionCounter++] = previousActionIndex; actionIndices[actionCounter++] = leftSideActionIndex;
} }
boolean shouldShowPauseButton = shouldShowPauseButton(player); boolean shouldShowPauseButton = shouldShowPauseButton(player);
if (pauseActionIndex != -1 && shouldShowPauseButton) { if (pauseActionIndex != -1 && shouldShowPauseButton) {
@ -1270,8 +1340,8 @@ public class PlayerNotificationManager {
} else if (playActionIndex != -1 && !shouldShowPauseButton) { } else if (playActionIndex != -1 && !shouldShowPauseButton) {
actionIndices[actionCounter++] = playActionIndex; actionIndices[actionCounter++] = playActionIndex;
} }
if (nextActionIndex != -1) { if (rightSideActionIndex != -1) {
actionIndices[actionCounter++] = nextActionIndex; actionIndices[actionCounter++] = rightSideActionIndex;
} }
return Arrays.copyOf(actionIndices, actionCounter); return Arrays.copyOf(actionIndices, actionCounter);
} }