Commit 92507e02 by tonihei Committed by kim-vde

Remove ExoPlayerImpl inheritance from BasePlayer.

This inheritance is really confusing because ExoPlayerImpl is not
a full Player interface implementation. It also claims to be an
ExoPlayer implementation in the Javadoc which isn't true in its
current state.

Removing the inheritance also allows to clean up some unused methods.

PiperOrigin-RevId: 411756963
parent da80b17a
......@@ -1092,7 +1092,7 @@ public final class CastPlayer extends BasePlayer {
private void updateAvailableCommandsAndNotifyIfChanged() {
Commands previousAvailableCommands = availableCommands;
availableCommands = getAvailableCommands(PERMANENT_AVAILABLE_COMMANDS);
availableCommands = Util.getAvailableCommands(/* player= */ this, PERMANENT_AVAILABLE_COMMANDS);
if (!availableCommands.equals(previousAvailableCommands)) {
listeners.queueEvent(
Player.EVENT_AVAILABLE_COMMANDS_CHANGED,
......
......@@ -382,37 +382,6 @@ public abstract class BasePlayer implements Player {
: timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs();
}
/**
* Returns the {@link Commands} available in the player.
*
* @param permanentAvailableCommands The commands permanently available in the player.
* @return The available {@link Commands}.
*/
protected Commands getAvailableCommands(Commands permanentAvailableCommands) {
return new Commands.Builder()
.addAll(permanentAvailableCommands)
.addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd())
.addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentMediaItemSeekable() && !isPlayingAd())
.addIf(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, hasPreviousMediaItem() && !isPlayingAd())
.addIf(
COMMAND_SEEK_TO_PREVIOUS,
!getCurrentTimeline().isEmpty()
&& (hasPreviousMediaItem()
|| !isCurrentMediaItemLive()
|| isCurrentMediaItemSeekable())
&& !isPlayingAd())
.addIf(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, hasNextMediaItem() && !isPlayingAd())
.addIf(
COMMAND_SEEK_TO_NEXT,
!getCurrentTimeline().isEmpty()
&& (hasNextMediaItem() || (isCurrentMediaItemLive() && isCurrentMediaItemDynamic()))
&& !isPlayingAd())
.addIf(COMMAND_SEEK_TO_MEDIA_ITEM, !isPlayingAd())
.addIf(COMMAND_SEEK_BACK, isCurrentMediaItemSeekable() && !isPlayingAd())
.addIf(COMMAND_SEEK_FORWARD, isCurrentMediaItemSeekable() && !isPlayingAd())
.build();
}
@RepeatMode
private int getRepeatModeForNavigation() {
@RepeatMode int repeatMode = getRepeatMode();
......
......@@ -16,6 +16,15 @@
package com.google.android.exoplayer2.util;
import static android.content.Context.UI_MODE_SERVICE;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_DEFAULT_POSITION;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_MEDIA_ITEM;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS;
import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static java.lang.Math.abs;
import static java.lang.Math.max;
......@@ -63,6 +72,8 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.Commands;
import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import java.io.ByteArrayOutputStream;
......@@ -2477,6 +2488,43 @@ public final class Util {
}
}
/**
* Returns the {@link Commands} available in the {@link Player}.
*
* @param player The {@link Player}.
* @param permanentAvailableCommands The commands permanently available in the player.
* @return The available {@link Commands}.
*/
public static Commands getAvailableCommands(Player player, Commands permanentAvailableCommands) {
boolean isPlayingAd = player.isPlayingAd();
boolean isCurrentMediaItemSeekable = player.isCurrentMediaItemSeekable();
boolean hasPreviousMediaItem = player.hasPreviousMediaItem();
boolean hasNextMediaItem = player.hasNextMediaItem();
boolean isCurrentMediaItemLive = player.isCurrentMediaItemLive();
boolean isCurrentMediaItemDynamic = player.isCurrentMediaItemDynamic();
boolean isTimelineEmpty = player.getCurrentTimeline().isEmpty();
return new Commands.Builder()
.addAll(permanentAvailableCommands)
.addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd)
.addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentMediaItemSeekable && !isPlayingAd)
.addIf(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, hasPreviousMediaItem && !isPlayingAd)
.addIf(
COMMAND_SEEK_TO_PREVIOUS,
!isTimelineEmpty
&& (hasPreviousMediaItem || !isCurrentMediaItemLive || isCurrentMediaItemSeekable)
&& !isPlayingAd)
.addIf(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, hasNextMediaItem && !isPlayingAd)
.addIf(
COMMAND_SEEK_TO_NEXT,
!isTimelineEmpty
&& (hasNextMediaItem || (isCurrentMediaItemLive && isCurrentMediaItemDynamic))
&& !isPlayingAd)
.addIf(COMMAND_SEEK_TO_MEDIA_ITEM, !isPlayingAd)
.addIf(COMMAND_SEEK_BACK, isCurrentMediaItemSeekable && !isPlayingAd)
.addIf(COMMAND_SEEK_FORWARD, isCurrentMediaItemSeekable && !isPlayingAd)
.build();
}
@Nullable
private static String getSystemProperty(String name) {
try {
......
......@@ -1351,7 +1351,6 @@ public class SimpleExoPlayer extends BasePlayer
}
@Override
@Nullable
public TrackSelector getTrackSelector() {
verifyApplicationThread();
return player.getTrackSelector();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment