package androidx.media3.session;

import android.app.PendingIntent;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.TextureView;
import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.DeviceInfo;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MediaLibraryInfo;
import androidx.media3.common.MediaMetadata;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.Rating;
import androidx.media3.common.Timeline;
import androidx.media3.common.TrackSelectionParameters;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
import androidx.media3.common.text.CueGroup;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Consumer;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Size;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.datasource.DataSourceBitmapLoader;
import androidx.media3.session.legacy.MediaBrowserCompat;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotMock;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.checkerframework.checker.initialization.qual.NotOnlyInitialized;

/* JADX INFO: loaded from: classes.dex */
@DoNotMock
public class MediaController implements Player {

    @UnstableApi
    protected static final long DEFAULT_PLATFORM_CALLBACK_AGGREGATION_TIMEOUT_MS = 100;

    @UnstableApi
    public static final String KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG = "androidx.media3.session.MediaNotificationManager";

    @UnstableApi
    public static final long RELEASE_UNBIND_TIMEOUT_MS = 30000;
    private static final String TAG = "MediaController";
    private static final String WRONG_THREAD_ERROR_MESSAGE = "MediaController method is called from a wrong thread. See javadoc of MediaController for details.";
    final Handler applicationHandler;
    final ConnectionCallback connectionCallback;
    private boolean connectionNotified;

    @NotOnlyInitialized
    private final MediaControllerImpl impl;
    final Listener listener;
    private final int maxCommandsForMediaItems;
    private boolean released;
    private long timeDiffMs;
    private final Timeline.Window window;

    public static final class Builder {
        private androidx.media3.common.util.BitmapLoader bitmapLoader;
        private final Context context;
        private int maxCommandsForMediaItems;
        private final SessionToken token;
        private Bundle connectionHints = Bundle.EMPTY;
        private Listener listener = new Listener() { // from class: androidx.media3.session.MediaController.Builder.1
        };
        private Looper applicationLooper = Util.getCurrentOrMainLooper();
        private long platformSessionCallbackAggregationTimeoutMs = 100;

        public Builder(Context context, SessionToken sessionToken) {
            this.context = (Context) Assertions.checkNotNull(context);
            this.token = (SessionToken) Assertions.checkNotNull(sessionToken);
        }

        /* JADX WARN: Type inference failed for: r11v0, types: [androidx.media3.session.MediaController$ConnectionCallback, androidx.media3.session.MediaControllerHolder, com.google.common.util.concurrent.ListenableFuture] */
        public ListenableFuture buildAsync() {
            final ?? mediaControllerHolder = new MediaControllerHolder(this.applicationLooper);
            if (this.token.isLegacySession() && this.bitmapLoader == null) {
                this.bitmapLoader = new CacheBitmapLoader(new DataSourceBitmapLoader(this.context));
            }
            final MediaController mediaController = new MediaController(this.context, this.token, this.connectionHints, this.listener, this.applicationLooper, mediaControllerHolder, this.bitmapLoader, this.maxCommandsForMediaItems, this.platformSessionCallbackAggregationTimeoutMs);
            Util.postOrRun(new Handler(this.applicationLooper), new Runnable() { // from class: androidx.media3.session.s
                @Override // java.lang.Runnable
                public final void run() {
                    mediaControllerHolder.setController(mediaController);
                }
            });
            return mediaControllerHolder;
        }

        @CanIgnoreReturnValue
        @UnstableApi
        public Builder experimentalSetPlatformSessionCallbackAggregationTimeoutMs(long j2) {
            this.platformSessionCallbackAggregationTimeoutMs = j2;
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setApplicationLooper(Looper looper) {
            this.applicationLooper = (Looper) Assertions.checkNotNull(looper);
            return this;
        }

        @CanIgnoreReturnValue
        @UnstableApi
        public Builder setBitmapLoader(androidx.media3.common.util.BitmapLoader bitmapLoader) {
            this.bitmapLoader = (androidx.media3.common.util.BitmapLoader) Assertions.checkNotNull(bitmapLoader);
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setConnectionHints(Bundle bundle) {
            this.connectionHints = new Bundle((Bundle) Assertions.checkNotNull(bundle));
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setListener(Listener listener) {
            this.listener = (Listener) Assertions.checkNotNull(listener);
            return this;
        }

        @CanIgnoreReturnValue
        @UnstableApi
        public Builder setMaxCommandsForMediaItems(int i2) {
            Assertions.checkArgument(i2 >= 0);
            this.maxCommandsForMediaItems = i2;
            return this;
        }
    }

    interface ConnectionCallback {
        void onAccepted();

        void onRejected();
    }

    public interface Listener {
        default void onAvailableSessionCommandsChanged(MediaController mediaController, SessionCommands sessionCommands) {
        }

        default ListenableFuture onCustomCommand(MediaController mediaController, SessionCommand sessionCommand, Bundle bundle) {
            return Futures.immediateFuture(new SessionResult(-6));
        }

        default void onCustomLayoutChanged(MediaController mediaController, List<CommandButton> list) {
        }

        default void onDisconnected(MediaController mediaController) {
        }

        @UnstableApi
        default void onError(MediaController mediaController, SessionError sessionError) {
        }

        default void onExtrasChanged(MediaController mediaController, Bundle bundle) {
        }

        @UnstableApi
        default void onMediaButtonPreferencesChanged(MediaController mediaController, List<CommandButton> list) {
        }

        @UnstableApi
        default void onSessionActivityChanged(MediaController mediaController, @Nullable PendingIntent pendingIntent) {
        }

        default ListenableFuture onSetCustomLayout(MediaController mediaController, List<CommandButton> list) {
            return Futures.immediateFuture(new SessionResult(-6));
        }
    }

    interface MediaControllerImpl {
        void addListener(Player.Listener listener);

        void addMediaItem(int i2, MediaItem mediaItem);

        void addMediaItem(MediaItem mediaItem);

        void addMediaItems(int i2, List<MediaItem> list);

        void addMediaItems(List<MediaItem> list);

        void clearMediaItems();

        void clearVideoSurface();

        void clearVideoSurface(@Nullable Surface surface);

        void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder);

        void clearVideoSurfaceView(@Nullable SurfaceView surfaceView);

        void clearVideoTextureView(@Nullable TextureView textureView);

        void connect();

        void decreaseDeviceVolume();

        void decreaseDeviceVolume(int i2);

        AudioAttributes getAudioAttributes();

        Player.Commands getAvailableCommands();

        SessionCommands getAvailableSessionCommands();

        @Nullable
        IMediaController getBinder();

        @Nullable
        MediaBrowserCompat getBrowserCompat();

        int getBufferedPercentage();

        long getBufferedPosition();

        ImmutableList<CommandButton> getCommandButtonsForMediaItem(MediaItem mediaItem);

        @Nullable
        SessionToken getConnectedToken();

        Bundle getConnectionHints();

        long getContentBufferedPosition();

        long getContentDuration();

        long getContentPosition();

        Context getContext();

        int getCurrentAdGroupIndex();

        int getCurrentAdIndexInAdGroup();

        CueGroup getCurrentCues();

        long getCurrentLiveOffset();

        int getCurrentMediaItemIndex();

        int getCurrentPeriodIndex();

        long getCurrentPosition();

        Timeline getCurrentTimeline();

        Tracks getCurrentTracks();

        ImmutableList<CommandButton> getCustomLayout();

        DeviceInfo getDeviceInfo();

        int getDeviceVolume();

        long getDuration();

        long getMaxSeekToPreviousPosition();

        ImmutableList<CommandButton> getMediaButtonPreferences();

        MediaMetadata getMediaMetadata();

        int getNextMediaItemIndex();

        boolean getPlayWhenReady();

        PlaybackParameters getPlaybackParameters();

        int getPlaybackState();

        int getPlaybackSuppressionReason();

        @Nullable
        PlaybackException getPlayerError();

        MediaMetadata getPlaylistMetadata();

        int getPreviousMediaItemIndex();

        int getRepeatMode();

        long getSeekBackIncrement();

        long getSeekForwardIncrement();

        @Nullable
        PendingIntent getSessionActivity();

        Bundle getSessionExtras();

        boolean getShuffleModeEnabled();

        Size getSurfaceSize();

        long getTotalBufferedDuration();

        TrackSelectionParameters getTrackSelectionParameters();

        VideoSize getVideoSize();

        float getVolume();

        boolean hasNextMediaItem();

        boolean hasPreviousMediaItem();

        void increaseDeviceVolume();

        void increaseDeviceVolume(int i2);

        boolean isConnected();

        boolean isDeviceMuted();

        boolean isLoading();

        boolean isPlaying();

        boolean isPlayingAd();

        void moveMediaItem(int i2, int i3);

        void moveMediaItems(int i2, int i3, int i4);

        void pause();

        void play();

        void prepare();

        void release();

        void removeListener(Player.Listener listener);

        void removeMediaItem(int i2);

        void removeMediaItems(int i2, int i3);

        void replaceMediaItem(int i2, MediaItem mediaItem);

        void replaceMediaItems(int i2, int i3, List<MediaItem> list);

        void seekBack();

        void seekForward();

        void seekTo(int i2, long j2);

        void seekTo(long j2);

        void seekToDefaultPosition();

        void seekToDefaultPosition(int i2);

        void seekToNext();

        void seekToNextMediaItem();

        void seekToPrevious();

        void seekToPreviousMediaItem();

        ListenableFuture sendCustomCommand(SessionCommand sessionCommand, Bundle bundle);

        void setAudioAttributes(AudioAttributes audioAttributes, boolean z2);

        void setDeviceMuted(boolean z2);

        void setDeviceMuted(boolean z2, int i2);

        void setDeviceVolume(int i2);

        void setDeviceVolume(int i2, int i3);

        void setMediaItem(MediaItem mediaItem);

        void setMediaItem(MediaItem mediaItem, long j2);

        void setMediaItem(MediaItem mediaItem, boolean z2);

        void setMediaItems(List<MediaItem> list);

        void setMediaItems(List<MediaItem> list, int i2, long j2);

        void setMediaItems(List<MediaItem> list, boolean z2);

        void setPlayWhenReady(boolean z2);

        void setPlaybackParameters(PlaybackParameters playbackParameters);

        void setPlaybackSpeed(float f2);

        void setPlaylistMetadata(MediaMetadata mediaMetadata);

        ListenableFuture setRating(Rating rating);

        ListenableFuture setRating(String str, Rating rating);

        void setRepeatMode(int i2);

        void setShuffleModeEnabled(boolean z2);

        void setTrackSelectionParameters(TrackSelectionParameters trackSelectionParameters);

        void setVideoSurface(@Nullable Surface surface);

        void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder);

        void setVideoSurfaceView(@Nullable SurfaceView surfaceView);

        void setVideoTextureView(@Nullable TextureView textureView);

        void setVolume(float f2);

        void stop();
    }

    MediaController(Context context, SessionToken sessionToken, Bundle bundle, Listener listener, Looper looper, ConnectionCallback connectionCallback, @Nullable androidx.media3.common.util.BitmapLoader bitmapLoader, int i2, long j2) {
        Assertions.checkNotNull(context, "context must not be null");
        Assertions.checkNotNull(sessionToken, "token must not be null");
        Log.i(TAG, "Init " + Integer.toHexString(System.identityHashCode(this)) + " [AndroidXMedia3/1.8.0] [" + Util.DEVICE_DEBUG_INFO + "]");
        this.window = new Timeline.Window();
        this.timeDiffMs = -9223372036854775807L;
        this.listener = listener;
        this.applicationHandler = new Handler(looper);
        this.connectionCallback = connectionCallback;
        this.maxCommandsForMediaItems = i2;
        MediaControllerImpl mediaControllerImplCreateImpl = createImpl(context, sessionToken, bundle, looper, bitmapLoader, j2);
        this.impl = mediaControllerImplCreateImpl;
        mediaControllerImplCreateImpl.connect();
    }

    private static ListenableFuture createDisconnectedFuture() {
        return Futures.immediateFuture(new SessionResult(-100));
    }

    private /* synthetic */ void lambda$release$0(Listener listener) {
        listener.onDisconnected(this);
    }

    public static void releaseFuture(Future<? extends MediaController> future) {
        if (future.cancel(false)) {
            return;
        }
        try {
            ((MediaController) Futures.getDone(future)).release();
        } catch (CancellationException | ExecutionException e2) {
            Log.w(TAG, "MediaController future failed (so we couldn't release it)", e2);
        }
    }

    private void verifyApplicationThread() {
        Assertions.checkState(Looper.myLooper() == getApplicationLooper(), WRONG_THREAD_ERROR_MESSAGE);
    }

    public final void addListener(Player.Listener listener) {
        Assertions.checkNotNull(listener, "listener must not be null");
        this.impl.addListener(listener);
    }

    public final void addMediaItem(MediaItem mediaItem) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.addMediaItem(mediaItem);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring addMediaItem().");
        }
    }

    public final void addMediaItems(List<MediaItem> list) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.addMediaItems(list);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring addMediaItems().");
        }
    }

    public final boolean canAdvertiseSession() {
        return false;
    }

    public final void clearMediaItems() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.clearMediaItems();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring clearMediaItems().");
        }
    }

    public final void clearVideoSurface() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.clearVideoSurface();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring clearVideoSurface().");
        }
    }

    public final void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.clearVideoSurfaceHolder(surfaceHolder);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring clearVideoSurfaceHolder().");
        }
    }

    public final void clearVideoSurfaceView(@Nullable SurfaceView surfaceView) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.clearVideoSurfaceView(surfaceView);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring clearVideoSurfaceView().");
        }
    }

    public final void clearVideoTextureView(@Nullable TextureView textureView) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.clearVideoTextureView(textureView);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring clearVideoTextureView().");
        }
    }

    MediaControllerImpl createImpl(Context context, SessionToken sessionToken, Bundle bundle, Looper looper, @Nullable androidx.media3.common.util.BitmapLoader bitmapLoader, long j2) {
        return sessionToken.isLegacySession() ? new MediaControllerImplLegacy(context, this, sessionToken, bundle, looper, (androidx.media3.common.util.BitmapLoader) Assertions.checkNotNull(bitmapLoader), j2) : new MediaControllerImplBase(context, this, sessionToken, bundle, looper);
    }

    @Deprecated
    public final void decreaseDeviceVolume() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.decreaseDeviceVolume();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring decreaseDeviceVolume().");
        }
    }

    public final Looper getApplicationLooper() {
        return this.applicationHandler.getLooper();
    }

    public final AudioAttributes getAudioAttributes() {
        verifyApplicationThread();
        return !isConnected() ? AudioAttributes.DEFAULT : this.impl.getAudioAttributes();
    }

    public final Player.Commands getAvailableCommands() {
        verifyApplicationThread();
        return !isConnected() ? Player.Commands.EMPTY : this.impl.getAvailableCommands();
    }

    public final SessionCommands getAvailableSessionCommands() {
        verifyApplicationThread();
        return !isConnected() ? SessionCommands.EMPTY : this.impl.getAvailableSessionCommands();
    }

    @Nullable
    @VisibleForTesting(otherwise = 5)
    final IMediaController getBinder() {
        return this.impl.getBinder();
    }

    @IntRange(from = 0, to = 100)
    public final int getBufferedPercentage() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getBufferedPercentage();
        }
        return 0;
    }

    public final long getBufferedPosition() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getBufferedPosition();
        }
        return 0L;
    }

    @UnstableApi
    public final ImmutableList<CommandButton> getCommandButtonsForMediaItem(MediaItem mediaItem) {
        return this.impl.getCommandButtonsForMediaItem(mediaItem);
    }

    @Nullable
    public final SessionToken getConnectedToken() {
        if (isConnected()) {
            return this.impl.getConnectedToken();
        }
        return null;
    }

    Bundle getConnectionHints() {
        return this.impl.getConnectionHints();
    }

    public final long getContentBufferedPosition() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getContentBufferedPosition();
        }
        return 0L;
    }

    public final long getContentDuration() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getContentDuration();
        }
        return -9223372036854775807L;
    }

    public final long getContentPosition() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getContentPosition();
        }
        return 0L;
    }

    public final int getCurrentAdGroupIndex() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getCurrentAdGroupIndex();
        }
        return -1;
    }

    public final int getCurrentAdIndexInAdGroup() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getCurrentAdIndexInAdGroup();
        }
        return -1;
    }

    public final CueGroup getCurrentCues() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getCurrentCues() : CueGroup.EMPTY_TIME_ZERO;
    }

    public final long getCurrentLiveOffset() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getCurrentLiveOffset();
        }
        return -9223372036854775807L;
    }

    @Nullable
    @UnstableApi
    public final Object getCurrentManifest() {
        return null;
    }

    @Nullable
    public final MediaItem getCurrentMediaItem() {
        Timeline currentTimeline = getCurrentTimeline();
        if (currentTimeline.isEmpty()) {
            return null;
        }
        return currentTimeline.getWindow(getCurrentMediaItemIndex(), this.window).mediaItem;
    }

    public final int getCurrentMediaItemIndex() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getCurrentMediaItemIndex();
        }
        return -1;
    }

    public final int getCurrentPeriodIndex() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getCurrentPeriodIndex();
        }
        return -1;
    }

    public final long getCurrentPosition() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getCurrentPosition();
        }
        return 0L;
    }

    public final Timeline getCurrentTimeline() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getCurrentTimeline() : Timeline.EMPTY;
    }

    public final Tracks getCurrentTracks() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getCurrentTracks() : Tracks.EMPTY;
    }

    @UnstableApi
    @Deprecated
    public final int getCurrentWindowIndex() {
        return getCurrentMediaItemIndex();
    }

    public final ImmutableList<CommandButton> getCustomLayout() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getCustomLayout() : ImmutableList.of();
    }

    public final DeviceInfo getDeviceInfo() {
        verifyApplicationThread();
        return !isConnected() ? DeviceInfo.UNKNOWN : this.impl.getDeviceInfo();
    }

    @IntRange(from = 0)
    public final int getDeviceVolume() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getDeviceVolume();
        }
        return 0;
    }

    public final long getDuration() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getDuration();
        }
        return -9223372036854775807L;
    }

    int getMaxCommandsForMediaItems() {
        return this.maxCommandsForMediaItems;
    }

    public final long getMaxSeekToPreviousPosition() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getMaxSeekToPreviousPosition();
        }
        return 0L;
    }

    @UnstableApi
    public final ImmutableList<CommandButton> getMediaButtonPreferences() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getMediaButtonPreferences() : ImmutableList.of();
    }

    public final MediaItem getMediaItemAt(int i2) {
        return getCurrentTimeline().getWindow(i2, this.window).mediaItem;
    }

    public final int getMediaItemCount() {
        return getCurrentTimeline().getWindowCount();
    }

    public final MediaMetadata getMediaMetadata() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getMediaMetadata() : MediaMetadata.EMPTY;
    }

    public final int getNextMediaItemIndex() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getNextMediaItemIndex();
        }
        return -1;
    }

    @UnstableApi
    @Deprecated
    public final int getNextWindowIndex() {
        return getNextMediaItemIndex();
    }

    public final boolean getPlayWhenReady() {
        verifyApplicationThread();
        return isConnected() && this.impl.getPlayWhenReady();
    }

    public final PlaybackParameters getPlaybackParameters() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getPlaybackParameters() : PlaybackParameters.DEFAULT;
    }

    public final int getPlaybackState() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getPlaybackState();
        }
        return 1;
    }

    public final int getPlaybackSuppressionReason() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getPlaybackSuppressionReason();
        }
        return 0;
    }

    @Nullable
    public final PlaybackException getPlayerError() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getPlayerError();
        }
        return null;
    }

    public final MediaMetadata getPlaylistMetadata() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getPlaylistMetadata() : MediaMetadata.EMPTY;
    }

    public final int getPreviousMediaItemIndex() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getPreviousMediaItemIndex();
        }
        return -1;
    }

    @UnstableApi
    @Deprecated
    public final int getPreviousWindowIndex() {
        return getPreviousMediaItemIndex();
    }

    public final int getRepeatMode() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getRepeatMode();
        }
        return 0;
    }

    public final long getSeekBackIncrement() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getSeekBackIncrement();
        }
        return 0L;
    }

    public final long getSeekForwardIncrement() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getSeekForwardIncrement();
        }
        return 0L;
    }

    @Nullable
    public final PendingIntent getSessionActivity() {
        if (isConnected()) {
            return this.impl.getSessionActivity();
        }
        return null;
    }

    public final Bundle getSessionExtras() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getSessionExtras() : Bundle.EMPTY;
    }

    public final boolean getShuffleModeEnabled() {
        verifyApplicationThread();
        return isConnected() && this.impl.getShuffleModeEnabled();
    }

    @UnstableApi
    public final Size getSurfaceSize() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getSurfaceSize() : Size.UNKNOWN;
    }

    final long getTimeDiffMs() {
        return this.timeDiffMs;
    }

    public final long getTotalBufferedDuration() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getTotalBufferedDuration();
        }
        return 0L;
    }

    public final TrackSelectionParameters getTrackSelectionParameters() {
        verifyApplicationThread();
        return !isConnected() ? TrackSelectionParameters.DEFAULT : this.impl.getTrackSelectionParameters();
    }

    public final VideoSize getVideoSize() {
        verifyApplicationThread();
        return isConnected() ? this.impl.getVideoSize() : VideoSize.UNKNOWN;
    }

    @FloatRange(from = com.jsyn.unitgen.u.FALSE, to = com.jsyn.unitgen.u.TRUE)
    public final float getVolume() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.getVolume();
        }
        return 1.0f;
    }

    public final boolean hasNextMediaItem() {
        verifyApplicationThread();
        return isConnected() && this.impl.hasNextMediaItem();
    }

    public final boolean hasPreviousMediaItem() {
        verifyApplicationThread();
        return isConnected() && this.impl.hasPreviousMediaItem();
    }

    @Deprecated
    public final void increaseDeviceVolume() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.increaseDeviceVolume();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring increaseDeviceVolume().");
        }
    }

    public final boolean isCommandAvailable(int i2) {
        return getAvailableCommands().contains(i2);
    }

    public final boolean isConnected() {
        return this.impl.isConnected();
    }

    public final boolean isCurrentMediaItemDynamic() {
        verifyApplicationThread();
        Timeline currentTimeline = getCurrentTimeline();
        return !currentTimeline.isEmpty() && currentTimeline.getWindow(getCurrentMediaItemIndex(), this.window).isDynamic;
    }

    public final boolean isCurrentMediaItemLive() {
        verifyApplicationThread();
        Timeline currentTimeline = getCurrentTimeline();
        return !currentTimeline.isEmpty() && currentTimeline.getWindow(getCurrentMediaItemIndex(), this.window).isLive();
    }

    public final boolean isCurrentMediaItemSeekable() {
        verifyApplicationThread();
        Timeline currentTimeline = getCurrentTimeline();
        return !currentTimeline.isEmpty() && currentTimeline.getWindow(getCurrentMediaItemIndex(), this.window).isSeekable;
    }

    @UnstableApi
    @Deprecated
    public final boolean isCurrentWindowDynamic() {
        return isCurrentMediaItemDynamic();
    }

    @UnstableApi
    @Deprecated
    public final boolean isCurrentWindowLive() {
        return isCurrentMediaItemLive();
    }

    @UnstableApi
    @Deprecated
    public final boolean isCurrentWindowSeekable() {
        return isCurrentMediaItemSeekable();
    }

    public final boolean isDeviceMuted() {
        verifyApplicationThread();
        if (isConnected()) {
            return this.impl.isDeviceMuted();
        }
        return false;
    }

    public final boolean isLoading() {
        verifyApplicationThread();
        return isConnected() && this.impl.isLoading();
    }

    public final boolean isPlaying() {
        verifyApplicationThread();
        return isConnected() && this.impl.isPlaying();
    }

    public final boolean isPlayingAd() {
        verifyApplicationThread();
        return isConnected() && this.impl.isPlayingAd();
    }

    public final boolean isSessionCommandAvailable(int i2) {
        return getAvailableSessionCommands().contains(i2);
    }

    public final void moveMediaItem(int i2, int i3) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.moveMediaItem(i2, i3);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring moveMediaItem().");
        }
    }

    public final void moveMediaItems(int i2, int i3, int i4) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.moveMediaItems(i2, i3, i4);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring moveMediaItems().");
        }
    }

    final void notifyAccepted() {
        Assertions.checkState(Looper.myLooper() == getApplicationLooper());
        Assertions.checkState(!this.connectionNotified);
        this.connectionNotified = true;
        this.connectionCallback.onAccepted();
    }

    final void notifyControllerListener(Consumer<Listener> consumer) {
        Assertions.checkState(Looper.myLooper() == getApplicationLooper());
        consumer.accept(this.listener);
    }

    public final void pause() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.pause();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring pause().");
        }
    }

    public final void play() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.play();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring play().");
        }
    }

    public final void prepare() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.prepare();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring prepare().");
        }
    }

    public final void release() {
        verifyApplicationThread();
        if (this.released) {
            return;
        }
        Log.i(TAG, "Release " + Integer.toHexString(System.identityHashCode(this)) + " [AndroidXMedia3/1.8.0] [" + Util.DEVICE_DEBUG_INFO + "] [" + MediaLibraryInfo.registeredModules() + "]");
        this.released = true;
        this.applicationHandler.removeCallbacksAndMessages(null);
        try {
            this.impl.release();
        } catch (Exception e2) {
            Log.d(TAG, "Exception while releasing impl", e2);
        }
        if (this.connectionNotified) {
            notifyControllerListener(new Consumer() { // from class: androidx.media3.session.r
            });
        } else {
            this.connectionNotified = true;
            this.connectionCallback.onRejected();
        }
    }

    public final void removeListener(Player.Listener listener) {
        verifyApplicationThread();
        Assertions.checkNotNull(listener, "listener must not be null");
        this.impl.removeListener(listener);
    }

    public final void removeMediaItem(int i2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.removeMediaItem(i2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring removeMediaItem().");
        }
    }

    public final void removeMediaItems(int i2, int i3) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.removeMediaItems(i2, i3);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring removeMediaItems().");
        }
    }

    public final void replaceMediaItem(int i2, MediaItem mediaItem) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.replaceMediaItem(i2, mediaItem);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring replaceMediaItem().");
        }
    }

    public final void replaceMediaItems(int i2, int i3, List<MediaItem> list) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.replaceMediaItems(i2, i3, list);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring replaceMediaItems().");
        }
    }

    final void runOnApplicationLooper(Runnable runnable) {
        Util.postOrRun(this.applicationHandler, runnable);
    }

    public final void seekBack() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekBack();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekBack().");
        }
    }

    public final void seekForward() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekForward();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekForward().");
        }
    }

    public final void seekTo(long j2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekTo(j2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekTo().");
        }
    }

    public final void seekToDefaultPosition() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekToDefaultPosition();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekTo().");
        }
    }

    public final void seekToNext() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekToNext();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekToNext().");
        }
    }

    public final void seekToNextMediaItem() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekToNextMediaItem();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekToNextMediaItem().");
        }
    }

    public final void seekToPrevious() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekToPrevious();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekToPrevious().");
        }
    }

    public final void seekToPreviousMediaItem() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.seekToPreviousMediaItem();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring seekToPreviousMediaItem().");
        }
    }

    public final ListenableFuture sendCustomCommand(SessionCommand sessionCommand, Bundle bundle) {
        verifyApplicationThread();
        Assertions.checkNotNull(sessionCommand, "command must not be null");
        Assertions.checkArgument(sessionCommand.commandCode == 0, "command must be a custom command");
        return isConnected() ? this.impl.sendCustomCommand(sessionCommand, bundle) : createDisconnectedFuture();
    }

    public final void setAudioAttributes(AudioAttributes audioAttributes, boolean z2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setAudioAttributes(audioAttributes, z2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setAudioAttributes().");
        }
    }

    @Deprecated
    public final void setDeviceMuted(boolean z2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setDeviceMuted(z2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setDeviceMuted().");
        }
    }

    @Deprecated
    public final void setDeviceVolume(@IntRange(from = 0) int i2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setDeviceVolume(i2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setDeviceVolume().");
        }
    }

    public final void setMediaItem(MediaItem mediaItem) {
        verifyApplicationThread();
        Assertions.checkNotNull(mediaItem, "mediaItems must not be null");
        if (isConnected()) {
            this.impl.setMediaItem(mediaItem);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setMediaItem().");
        }
    }

    public final void setMediaItems(List<MediaItem> list) {
        verifyApplicationThread();
        Assertions.checkNotNull(list, "mediaItems must not be null");
        for (int i2 = 0; i2 < list.size(); i2++) {
            Assertions.checkArgument(list.get(i2) != null, "items must not contain null, index=" + i2);
        }
        if (isConnected()) {
            this.impl.setMediaItems(list);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setMediaItems().");
        }
    }

    public final void setPlayWhenReady(boolean z2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setPlayWhenReady(z2);
        }
    }

    public final void setPlaybackParameters(PlaybackParameters playbackParameters) {
        verifyApplicationThread();
        Assertions.checkNotNull(playbackParameters, "playbackParameters must not be null");
        if (isConnected()) {
            this.impl.setPlaybackParameters(playbackParameters);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setPlaybackParameters().");
        }
    }

    public final void setPlaybackSpeed(float f2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setPlaybackSpeed(f2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setPlaybackSpeed().");
        }
    }

    public final void setPlaylistMetadata(MediaMetadata mediaMetadata) {
        verifyApplicationThread();
        Assertions.checkNotNull(mediaMetadata, "playlistMetadata must not be null");
        if (isConnected()) {
            this.impl.setPlaylistMetadata(mediaMetadata);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setPlaylistMetadata().");
        }
    }

    public final ListenableFuture setRating(String str, Rating rating) {
        verifyApplicationThread();
        Assertions.checkNotNull(str, "mediaId must not be null");
        Assertions.checkNotEmpty(str, "mediaId must not be empty");
        Assertions.checkNotNull(rating, "rating must not be null");
        return isConnected() ? this.impl.setRating(str, rating) : createDisconnectedFuture();
    }

    public final void setRepeatMode(int i2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setRepeatMode(i2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setRepeatMode().");
        }
    }

    public final void setShuffleModeEnabled(boolean z2) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setShuffleModeEnabled(z2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setShuffleMode().");
        }
    }

    @VisibleForTesting(otherwise = 5)
    final void setTimeDiffMs(long j2) {
        verifyApplicationThread();
        this.timeDiffMs = j2;
    }

    public final void setTrackSelectionParameters(TrackSelectionParameters trackSelectionParameters) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setTrackSelectionParameters().");
        }
        this.impl.setTrackSelectionParameters(trackSelectionParameters);
    }

    public final void setVideoSurface(@Nullable Surface surface) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setVideoSurface(surface);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setVideoSurface().");
        }
    }

    public final void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setVideoSurfaceHolder(surfaceHolder);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setVideoSurfaceHolder().");
        }
    }

    public final void setVideoSurfaceView(@Nullable SurfaceView surfaceView) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setVideoSurfaceView(surfaceView);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setVideoSurfaceView().");
        }
    }

    public final void setVideoTextureView(@Nullable TextureView textureView) {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.setVideoTextureView(textureView);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setVideoTextureView().");
        }
    }

    public final void setVolume(@FloatRange(from = com.jsyn.unitgen.u.FALSE, to = com.jsyn.unitgen.u.TRUE) float f2) {
        verifyApplicationThread();
        Assertions.checkArgument(f2 >= 0.0f && f2 <= 1.0f, "volume must be between 0 and 1");
        if (isConnected()) {
            this.impl.setVolume(f2);
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring setVolume().");
        }
    }

    public final void stop() {
        verifyApplicationThread();
        if (isConnected()) {
            this.impl.stop();
        } else {
            Log.w(TAG, "The controller is not connected. Ignoring stop().");
        }
    }

    public final boolean isSessionCommandAvailable(SessionCommand sessionCommand) {
        return getAvailableSessionCommands().contains(sessionCommand);
    }

    public final void addMediaItem(int i2, MediaItem mediaItem) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring addMediaItem().");
        } else {
            this.impl.addMediaItem(i2, mediaItem);
        }
    }

    public final void addMediaItems(int i2, List<MediaItem> list) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring addMediaItems().");
        } else {
            this.impl.addMediaItems(i2, list);
        }
    }

    public final void clearVideoSurface(@Nullable Surface surface) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring clearVideoSurface().");
        } else {
            this.impl.clearVideoSurface(surface);
        }
    }

    public final void decreaseDeviceVolume(int i2) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring decreaseDeviceVolume().");
        } else {
            this.impl.decreaseDeviceVolume(i2);
        }
    }

    public final void increaseDeviceVolume(int i2) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring increaseDeviceVolume().");
        } else {
            this.impl.increaseDeviceVolume(i2);
        }
    }

    public final void seekTo(int i2, long j2) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring seekTo().");
        } else {
            this.impl.seekTo(i2, j2);
        }
    }

    public final void seekToDefaultPosition(int i2) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring seekTo().");
        } else {
            this.impl.seekToDefaultPosition(i2);
        }
    }

    public final void setDeviceMuted(boolean z2, int i2) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setDeviceMuted().");
        } else {
            this.impl.setDeviceMuted(z2, i2);
        }
    }

    public final void setDeviceVolume(@IntRange(from = 0) int i2, int i3) {
        verifyApplicationThread();
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setDeviceVolume().");
        } else {
            this.impl.setDeviceVolume(i2, i3);
        }
    }

    public final void setMediaItem(MediaItem mediaItem, long j2) {
        verifyApplicationThread();
        Assertions.checkNotNull(mediaItem, "mediaItems must not be null");
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setMediaItem().");
        } else {
            this.impl.setMediaItem(mediaItem, j2);
        }
    }

    @UnstableApi
    public final ListenableFuture sendCustomCommand(SessionCommand sessionCommand, MediaItem mediaItem, Bundle bundle) {
        Bundle bundle2 = new Bundle(bundle);
        bundle2.putString("androidx.media.utils.extras.KEY_CUSTOM_BROWSER_ACTION_MEDIA_ITEM_ID", mediaItem.mediaId);
        return sendCustomCommand(sessionCommand, bundle2);
    }

    public final void setMediaItems(List<MediaItem> list, boolean z2) {
        verifyApplicationThread();
        Assertions.checkNotNull(list, "mediaItems must not be null");
        for (int i2 = 0; i2 < list.size(); i2++) {
            Assertions.checkArgument(list.get(i2) != null, "items must not contain null, index=" + i2);
        }
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setMediaItems().");
        } else {
            this.impl.setMediaItems(list, z2);
        }
    }

    public final ListenableFuture setRating(Rating rating) {
        verifyApplicationThread();
        Assertions.checkNotNull(rating, "rating must not be null");
        if (isConnected()) {
            return this.impl.setRating(rating);
        }
        return createDisconnectedFuture();
    }

    public final void setMediaItem(MediaItem mediaItem, boolean z2) {
        verifyApplicationThread();
        Assertions.checkNotNull(mediaItem, "mediaItems must not be null");
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setMediaItems().");
        } else {
            this.impl.setMediaItem(mediaItem, z2);
        }
    }

    public final void setMediaItems(List<MediaItem> list, int i2, long j2) {
        verifyApplicationThread();
        Assertions.checkNotNull(list, "mediaItems must not be null");
        for (int i3 = 0; i3 < list.size(); i3++) {
            Assertions.checkArgument(list.get(i3) != null, "items must not contain null, index=" + i3);
        }
        if (!isConnected()) {
            Log.w(TAG, "The controller is not connected. Ignoring setMediaItems().");
        } else {
            this.impl.setMediaItems(list, i2, j2);
        }
    }
}
