- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
653 lines
28 KiB
Java
653 lines
28 KiB
Java
package com.mbridge.msdk.playercommon.exoplayer2;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.util.Log;
|
|
import android.util.Pair;
|
|
import androidx.annotation.Nullable;
|
|
import com.ironsource.v8;
|
|
import com.mbridge.msdk.foundation.tools.af;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.Player;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.PlayerMessage;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.Timeline;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.source.MediaSource;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.source.TrackGroupArray;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelectionArray;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelector;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelectorResult;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.util.Clock;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
/* loaded from: classes4.dex */
|
|
final class ExoPlayerImpl implements ExoPlayer {
|
|
private static final String TAG = "ExoPlayerImpl";
|
|
private final TrackSelectorResult emptyTrackSelectorResult;
|
|
private final Handler eventHandler;
|
|
private boolean hasPendingPrepare;
|
|
private boolean hasPendingSeek;
|
|
private final ExoPlayerImplInternal internalPlayer;
|
|
private final Handler internalPlayerHandler;
|
|
private final CopyOnWriteArraySet<Player.EventListener> listeners;
|
|
private int maskingPeriodIndex;
|
|
private int maskingWindowIndex;
|
|
private long maskingWindowPositionMs;
|
|
private int pendingOperationAcks;
|
|
private final ArrayDeque<PlaybackInfoUpdate> pendingPlaybackInfoUpdates;
|
|
private final Timeline.Period period;
|
|
private boolean playWhenReady;
|
|
|
|
@Nullable
|
|
private ExoPlaybackException playbackError;
|
|
private PlaybackInfo playbackInfo;
|
|
private PlaybackParameters playbackParameters;
|
|
private final Renderer[] renderers;
|
|
private int repeatMode;
|
|
private boolean shuffleModeEnabled;
|
|
private final TrackSelector trackSelector;
|
|
private final Timeline.Window window;
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final boolean getPlayWhenReady() {
|
|
return this.playWhenReady;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
@Nullable
|
|
public final ExoPlaybackException getPlaybackError() {
|
|
return this.playbackError;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final PlaybackParameters getPlaybackParameters() {
|
|
return this.playbackParameters;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getRepeatMode() {
|
|
return this.repeatMode;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final boolean getShuffleModeEnabled() {
|
|
return this.shuffleModeEnabled;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final Player.TextComponent getTextComponent() {
|
|
return null;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final Player.VideoComponent getVideoComponent() {
|
|
return null;
|
|
}
|
|
|
|
@SuppressLint({"HandlerLeak"})
|
|
public ExoPlayerImpl(Renderer[] rendererArr, TrackSelector trackSelector, LoadControl loadControl, Clock clock) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Init ");
|
|
sb.append(Integer.toHexString(System.identityHashCode(this)));
|
|
sb.append(" [");
|
|
sb.append(ExoPlayerLibraryInfo.VERSION_SLASHY);
|
|
sb.append("] [");
|
|
sb.append(Util.DEVICE_DEBUG_INFO);
|
|
sb.append(v8.i.e);
|
|
Assertions.checkState(rendererArr.length > 0);
|
|
this.renderers = (Renderer[]) Assertions.checkNotNull(rendererArr);
|
|
this.trackSelector = (TrackSelector) Assertions.checkNotNull(trackSelector);
|
|
this.playWhenReady = false;
|
|
this.repeatMode = 0;
|
|
this.shuffleModeEnabled = false;
|
|
this.listeners = new CopyOnWriteArraySet<>();
|
|
TrackSelectorResult trackSelectorResult = new TrackSelectorResult(new RendererConfiguration[rendererArr.length], new TrackSelection[rendererArr.length], null);
|
|
this.emptyTrackSelectorResult = trackSelectorResult;
|
|
this.window = new Timeline.Window();
|
|
this.period = new Timeline.Period();
|
|
this.playbackParameters = PlaybackParameters.DEFAULT;
|
|
Handler handler = new Handler(Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper()) { // from class: com.mbridge.msdk.playercommon.exoplayer2.ExoPlayerImpl.1
|
|
@Override // android.os.Handler
|
|
public void handleMessage(Message message) {
|
|
ExoPlayerImpl.this.handleEvent(message);
|
|
}
|
|
};
|
|
this.eventHandler = handler;
|
|
this.playbackInfo = new PlaybackInfo(Timeline.EMPTY, 0L, TrackGroupArray.EMPTY, trackSelectorResult);
|
|
this.pendingPlaybackInfoUpdates = new ArrayDeque<>();
|
|
ExoPlayerImplInternal exoPlayerImplInternal = new ExoPlayerImplInternal(rendererArr, trackSelector, trackSelectorResult, loadControl, this.playWhenReady, this.repeatMode, this.shuffleModeEnabled, handler, this, clock);
|
|
this.internalPlayer = exoPlayerImplInternal;
|
|
this.internalPlayerHandler = new Handler(exoPlayerImplInternal.getPlaybackLooper());
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final Looper getPlaybackLooper() {
|
|
return this.internalPlayer.getPlaybackLooper();
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void addListener(Player.EventListener eventListener) {
|
|
this.listeners.add(eventListener);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void removeListener(Player.EventListener eventListener) {
|
|
this.listeners.remove(eventListener);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getPlaybackState() {
|
|
return this.playbackInfo.playbackState;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final void prepare(MediaSource mediaSource) {
|
|
prepare(mediaSource, true, true);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final void prepare(MediaSource mediaSource, boolean z, boolean z2) {
|
|
this.playbackError = null;
|
|
PlaybackInfo resetPlaybackInfo = getResetPlaybackInfo(z, z2, 2);
|
|
this.hasPendingPrepare = true;
|
|
this.pendingOperationAcks++;
|
|
this.internalPlayer.prepare(mediaSource, z, z2);
|
|
updatePlaybackInfo(resetPlaybackInfo, false, 4, 1, false, false);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void setPlayWhenReady(boolean z) {
|
|
if (this.playWhenReady != z) {
|
|
this.playWhenReady = z;
|
|
this.internalPlayer.setPlayWhenReady(z);
|
|
updatePlaybackInfo(this.playbackInfo, false, 4, 1, false, true);
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void setRepeatMode(int i) {
|
|
if (this.repeatMode != i) {
|
|
this.repeatMode = i;
|
|
this.internalPlayer.setRepeatMode(i);
|
|
Iterator<Player.EventListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onRepeatModeChanged(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void setShuffleModeEnabled(boolean z) {
|
|
if (this.shuffleModeEnabled != z) {
|
|
this.shuffleModeEnabled = z;
|
|
this.internalPlayer.setShuffleModeEnabled(z);
|
|
Iterator<Player.EventListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onShuffleModeEnabledChanged(z);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final boolean isLoading() {
|
|
return this.playbackInfo.isLoading;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void seekToDefaultPosition() {
|
|
seekToDefaultPosition(getCurrentWindowIndex());
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void seekToDefaultPosition(int i) {
|
|
seekTo(i, C.TIME_UNSET);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void seekTo(long j) {
|
|
seekTo(getCurrentWindowIndex(), j);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void seekTo(int i, long j) {
|
|
Timeline timeline = this.playbackInfo.timeline;
|
|
if (i < 0 || (!timeline.isEmpty() && i >= timeline.getWindowCount())) {
|
|
throw new IllegalSeekPositionException(timeline, i, j);
|
|
}
|
|
this.hasPendingSeek = true;
|
|
this.pendingOperationAcks++;
|
|
if (isPlayingAd()) {
|
|
Log.w(TAG, "seekTo ignored because an ad is playing");
|
|
this.eventHandler.obtainMessage(0, 1, -1, this.playbackInfo).sendToTarget();
|
|
return;
|
|
}
|
|
this.maskingWindowIndex = i;
|
|
if (timeline.isEmpty()) {
|
|
this.maskingWindowPositionMs = j == C.TIME_UNSET ? 0L : j;
|
|
this.maskingPeriodIndex = 0;
|
|
} else {
|
|
long defaultPositionUs = j == C.TIME_UNSET ? timeline.getWindow(i, this.window).getDefaultPositionUs() : C.msToUs(j);
|
|
Pair<Integer, Long> periodPosition = timeline.getPeriodPosition(this.window, this.period, i, defaultPositionUs);
|
|
this.maskingWindowPositionMs = C.usToMs(defaultPositionUs);
|
|
this.maskingPeriodIndex = ((Integer) periodPosition.first).intValue();
|
|
}
|
|
this.internalPlayer.seekTo(timeline, i, C.msToUs(j));
|
|
Iterator<Player.EventListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onPositionDiscontinuity(1);
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters) {
|
|
if (playbackParameters == null) {
|
|
playbackParameters = PlaybackParameters.DEFAULT;
|
|
}
|
|
this.internalPlayer.setPlaybackParameters(playbackParameters);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final void setSeekParameters(@Nullable SeekParameters seekParameters) {
|
|
if (seekParameters == null) {
|
|
seekParameters = SeekParameters.DEFAULT;
|
|
}
|
|
this.internalPlayer.setSeekParameters(seekParameters);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
@Nullable
|
|
public final Object getCurrentTag() {
|
|
int currentWindowIndex = getCurrentWindowIndex();
|
|
if (currentWindowIndex > this.playbackInfo.timeline.getWindowCount()) {
|
|
return null;
|
|
}
|
|
return this.playbackInfo.timeline.getWindow(currentWindowIndex, this.window, true).tag;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void stop() {
|
|
stop(false);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void stop(boolean z) {
|
|
if (z) {
|
|
this.playbackError = null;
|
|
}
|
|
PlaybackInfo resetPlaybackInfo = getResetPlaybackInfo(z, z, 1);
|
|
this.pendingOperationAcks++;
|
|
this.internalPlayer.stop(z);
|
|
updatePlaybackInfo(resetPlaybackInfo, false, 4, 1, false, false);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final void release() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Release ");
|
|
sb.append(Integer.toHexString(System.identityHashCode(this)));
|
|
sb.append(" [");
|
|
sb.append(ExoPlayerLibraryInfo.VERSION_SLASHY);
|
|
sb.append("] [");
|
|
sb.append(Util.DEVICE_DEBUG_INFO);
|
|
sb.append("] [");
|
|
sb.append(ExoPlayerLibraryInfo.registeredModules());
|
|
sb.append(v8.i.e);
|
|
this.internalPlayer.release();
|
|
this.eventHandler.removeCallbacksAndMessages(null);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final void sendMessages(ExoPlayer.ExoPlayerMessage... exoPlayerMessageArr) {
|
|
for (ExoPlayer.ExoPlayerMessage exoPlayerMessage : exoPlayerMessageArr) {
|
|
createMessage(exoPlayerMessage.target).setType(exoPlayerMessage.messageType).setPayload(exoPlayerMessage.message).send();
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final PlayerMessage createMessage(PlayerMessage.Target target) {
|
|
return new PlayerMessage(this.internalPlayer, target, this.playbackInfo.timeline, getCurrentWindowIndex(), this.internalPlayerHandler);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.ExoPlayer
|
|
public final void blockingSendMessages(ExoPlayer.ExoPlayerMessage... exoPlayerMessageArr) {
|
|
ArrayList<PlayerMessage> arrayList = new ArrayList();
|
|
for (ExoPlayer.ExoPlayerMessage exoPlayerMessage : exoPlayerMessageArr) {
|
|
arrayList.add(createMessage(exoPlayerMessage.target).setType(exoPlayerMessage.messageType).setPayload(exoPlayerMessage.message).send());
|
|
}
|
|
boolean z = false;
|
|
for (PlayerMessage playerMessage : arrayList) {
|
|
boolean z2 = true;
|
|
while (z2) {
|
|
try {
|
|
playerMessage.blockUntilDelivered();
|
|
z2 = false;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
} catch (TimeoutException e) {
|
|
af.b(TAG, e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getCurrentPeriodIndex() {
|
|
return shouldMaskPosition() ? this.maskingPeriodIndex : this.playbackInfo.periodId.periodIndex;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getCurrentWindowIndex() {
|
|
if (shouldMaskPosition()) {
|
|
return this.maskingWindowIndex;
|
|
}
|
|
PlaybackInfo playbackInfo = this.playbackInfo;
|
|
return playbackInfo.timeline.getPeriod(playbackInfo.periodId.periodIndex, this.period).windowIndex;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getNextWindowIndex() {
|
|
Timeline timeline = this.playbackInfo.timeline;
|
|
if (timeline.isEmpty()) {
|
|
return -1;
|
|
}
|
|
return timeline.getNextWindowIndex(getCurrentWindowIndex(), this.repeatMode, this.shuffleModeEnabled);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getPreviousWindowIndex() {
|
|
Timeline timeline = this.playbackInfo.timeline;
|
|
if (timeline.isEmpty()) {
|
|
return -1;
|
|
}
|
|
return timeline.getPreviousWindowIndex(getCurrentWindowIndex(), this.repeatMode, this.shuffleModeEnabled);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final long getDuration() {
|
|
Timeline timeline = this.playbackInfo.timeline;
|
|
if (timeline.isEmpty()) {
|
|
return C.TIME_UNSET;
|
|
}
|
|
if (isPlayingAd()) {
|
|
MediaSource.MediaPeriodId mediaPeriodId = this.playbackInfo.periodId;
|
|
timeline.getPeriod(mediaPeriodId.periodIndex, this.period);
|
|
return C.usToMs(this.period.getAdDurationUs(mediaPeriodId.adGroupIndex, mediaPeriodId.adIndexInAdGroup));
|
|
}
|
|
return timeline.getWindow(getCurrentWindowIndex(), this.window).getDurationMs();
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final long getCurrentPosition() {
|
|
return shouldMaskPosition() ? this.maskingWindowPositionMs : playbackInfoPositionUsToWindowPositionMs(this.playbackInfo.positionUs);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final long getBufferedPosition() {
|
|
return shouldMaskPosition() ? this.maskingWindowPositionMs : playbackInfoPositionUsToWindowPositionMs(this.playbackInfo.bufferedPositionUs);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getBufferedPercentage() {
|
|
long bufferedPosition = getBufferedPosition();
|
|
long duration = getDuration();
|
|
if (bufferedPosition == C.TIME_UNSET || duration == C.TIME_UNSET) {
|
|
return 0;
|
|
}
|
|
if (duration == 0) {
|
|
return 100;
|
|
}
|
|
return Util.constrainValue((int) ((bufferedPosition * 100) / duration), 0, 100);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final boolean isCurrentWindowDynamic() {
|
|
Timeline timeline = this.playbackInfo.timeline;
|
|
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), this.window).isDynamic;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final boolean isCurrentWindowSeekable() {
|
|
Timeline timeline = this.playbackInfo.timeline;
|
|
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), this.window).isSeekable;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final boolean isPlayingAd() {
|
|
return !shouldMaskPosition() && this.playbackInfo.periodId.isAd();
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getCurrentAdGroupIndex() {
|
|
if (isPlayingAd()) {
|
|
return this.playbackInfo.periodId.adGroupIndex;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getCurrentAdIndexInAdGroup() {
|
|
if (isPlayingAd()) {
|
|
return this.playbackInfo.periodId.adIndexInAdGroup;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final long getContentPosition() {
|
|
if (isPlayingAd()) {
|
|
PlaybackInfo playbackInfo = this.playbackInfo;
|
|
playbackInfo.timeline.getPeriod(playbackInfo.periodId.periodIndex, this.period);
|
|
return this.period.getPositionInWindowMs() + C.usToMs(this.playbackInfo.contentPositionUs);
|
|
}
|
|
return getCurrentPosition();
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getRendererCount() {
|
|
return this.renderers.length;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final int getRendererType(int i) {
|
|
return this.renderers[i].getTrackType();
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final TrackGroupArray getCurrentTrackGroups() {
|
|
return this.playbackInfo.trackGroups;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final TrackSelectionArray getCurrentTrackSelections() {
|
|
return this.playbackInfo.trackSelectorResult.selections;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final Timeline getCurrentTimeline() {
|
|
return this.playbackInfo.timeline;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player
|
|
public final Object getCurrentManifest() {
|
|
return this.playbackInfo.manifest;
|
|
}
|
|
|
|
public final void handleEvent(Message message) {
|
|
int i = message.what;
|
|
if (i == 0) {
|
|
PlaybackInfo playbackInfo = (PlaybackInfo) message.obj;
|
|
int i2 = message.arg1;
|
|
int i3 = message.arg2;
|
|
handlePlaybackInfo(playbackInfo, i2, i3 != -1, i3);
|
|
return;
|
|
}
|
|
if (i != 1) {
|
|
if (i == 2) {
|
|
ExoPlaybackException exoPlaybackException = (ExoPlaybackException) message.obj;
|
|
this.playbackError = exoPlaybackException;
|
|
Iterator<Player.EventListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onPlayerError(exoPlaybackException);
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalStateException();
|
|
}
|
|
PlaybackParameters playbackParameters = (PlaybackParameters) message.obj;
|
|
if (this.playbackParameters.equals(playbackParameters)) {
|
|
return;
|
|
}
|
|
this.playbackParameters = playbackParameters;
|
|
Iterator<Player.EventListener> it2 = this.listeners.iterator();
|
|
while (it2.hasNext()) {
|
|
it2.next().onPlaybackParametersChanged(playbackParameters);
|
|
}
|
|
}
|
|
|
|
private void handlePlaybackInfo(PlaybackInfo playbackInfo, int i, boolean z, int i2) {
|
|
int i3 = this.pendingOperationAcks - i;
|
|
this.pendingOperationAcks = i3;
|
|
if (i3 == 0) {
|
|
if (playbackInfo.startPositionUs == C.TIME_UNSET) {
|
|
playbackInfo = playbackInfo.fromNewPosition(playbackInfo.periodId, 0L, playbackInfo.contentPositionUs);
|
|
}
|
|
PlaybackInfo playbackInfo2 = playbackInfo;
|
|
if ((!this.playbackInfo.timeline.isEmpty() || this.hasPendingPrepare) && playbackInfo2.timeline.isEmpty()) {
|
|
this.maskingPeriodIndex = 0;
|
|
this.maskingWindowIndex = 0;
|
|
this.maskingWindowPositionMs = 0L;
|
|
}
|
|
int i4 = this.hasPendingPrepare ? 0 : 2;
|
|
boolean z2 = this.hasPendingSeek;
|
|
this.hasPendingPrepare = false;
|
|
this.hasPendingSeek = false;
|
|
updatePlaybackInfo(playbackInfo2, z, i2, i4, z2, false);
|
|
}
|
|
}
|
|
|
|
private PlaybackInfo getResetPlaybackInfo(boolean z, boolean z2, int i) {
|
|
if (z) {
|
|
this.maskingWindowIndex = 0;
|
|
this.maskingPeriodIndex = 0;
|
|
this.maskingWindowPositionMs = 0L;
|
|
} else {
|
|
this.maskingWindowIndex = getCurrentWindowIndex();
|
|
this.maskingPeriodIndex = getCurrentPeriodIndex();
|
|
this.maskingWindowPositionMs = getCurrentPosition();
|
|
}
|
|
Timeline timeline = z2 ? Timeline.EMPTY : this.playbackInfo.timeline;
|
|
Object obj = z2 ? null : this.playbackInfo.manifest;
|
|
PlaybackInfo playbackInfo = this.playbackInfo;
|
|
return new PlaybackInfo(timeline, obj, playbackInfo.periodId, playbackInfo.startPositionUs, playbackInfo.contentPositionUs, i, false, z2 ? TrackGroupArray.EMPTY : playbackInfo.trackGroups, z2 ? this.emptyTrackSelectorResult : playbackInfo.trackSelectorResult);
|
|
}
|
|
|
|
private void updatePlaybackInfo(PlaybackInfo playbackInfo, boolean z, int i, int i2, boolean z2, boolean z3) {
|
|
boolean z4 = !this.pendingPlaybackInfoUpdates.isEmpty();
|
|
this.pendingPlaybackInfoUpdates.addLast(new PlaybackInfoUpdate(playbackInfo, this.playbackInfo, this.listeners, this.trackSelector, z, i, i2, z2, this.playWhenReady, z3));
|
|
this.playbackInfo = playbackInfo;
|
|
if (z4) {
|
|
return;
|
|
}
|
|
while (!this.pendingPlaybackInfoUpdates.isEmpty()) {
|
|
this.pendingPlaybackInfoUpdates.peekFirst().notifyListeners();
|
|
this.pendingPlaybackInfoUpdates.removeFirst();
|
|
}
|
|
}
|
|
|
|
private long playbackInfoPositionUsToWindowPositionMs(long j) {
|
|
long usToMs = C.usToMs(j);
|
|
if (this.playbackInfo.periodId.isAd()) {
|
|
return usToMs;
|
|
}
|
|
PlaybackInfo playbackInfo = this.playbackInfo;
|
|
playbackInfo.timeline.getPeriod(playbackInfo.periodId.periodIndex, this.period);
|
|
return usToMs + this.period.getPositionInWindowMs();
|
|
}
|
|
|
|
private boolean shouldMaskPosition() {
|
|
return this.playbackInfo.timeline.isEmpty() || this.pendingOperationAcks > 0;
|
|
}
|
|
|
|
public static final class PlaybackInfoUpdate {
|
|
private final boolean isLoadingChanged;
|
|
private final Set<Player.EventListener> listeners;
|
|
private final boolean playWhenReady;
|
|
private final PlaybackInfo playbackInfo;
|
|
private final boolean playbackStateOrPlayWhenReadyChanged;
|
|
private final boolean positionDiscontinuity;
|
|
private final int positionDiscontinuityReason;
|
|
private final boolean seekProcessed;
|
|
private final int timelineChangeReason;
|
|
private final boolean timelineOrManifestChanged;
|
|
private final TrackSelector trackSelector;
|
|
private final boolean trackSelectorResultChanged;
|
|
|
|
public PlaybackInfoUpdate(PlaybackInfo playbackInfo, PlaybackInfo playbackInfo2, Set<Player.EventListener> set, TrackSelector trackSelector, boolean z, int i, int i2, boolean z2, boolean z3, boolean z4) {
|
|
this.playbackInfo = playbackInfo;
|
|
this.listeners = set;
|
|
this.trackSelector = trackSelector;
|
|
this.positionDiscontinuity = z;
|
|
this.positionDiscontinuityReason = i;
|
|
this.timelineChangeReason = i2;
|
|
this.seekProcessed = z2;
|
|
this.playWhenReady = z3;
|
|
this.playbackStateOrPlayWhenReadyChanged = z4 || playbackInfo2.playbackState != playbackInfo.playbackState;
|
|
this.timelineOrManifestChanged = (playbackInfo2.timeline == playbackInfo.timeline && playbackInfo2.manifest == playbackInfo.manifest) ? false : true;
|
|
this.isLoadingChanged = playbackInfo2.isLoading != playbackInfo.isLoading;
|
|
this.trackSelectorResultChanged = playbackInfo2.trackSelectorResult != playbackInfo.trackSelectorResult;
|
|
}
|
|
|
|
public final void notifyListeners() {
|
|
if (this.timelineOrManifestChanged || this.timelineChangeReason == 0) {
|
|
for (Player.EventListener eventListener : this.listeners) {
|
|
PlaybackInfo playbackInfo = this.playbackInfo;
|
|
eventListener.onTimelineChanged(playbackInfo.timeline, playbackInfo.manifest, this.timelineChangeReason);
|
|
}
|
|
}
|
|
if (this.positionDiscontinuity) {
|
|
Iterator<Player.EventListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onPositionDiscontinuity(this.positionDiscontinuityReason);
|
|
}
|
|
}
|
|
if (this.trackSelectorResultChanged) {
|
|
this.trackSelector.onSelectionActivated(this.playbackInfo.trackSelectorResult.info);
|
|
for (Player.EventListener eventListener2 : this.listeners) {
|
|
PlaybackInfo playbackInfo2 = this.playbackInfo;
|
|
eventListener2.onTracksChanged(playbackInfo2.trackGroups, playbackInfo2.trackSelectorResult.selections);
|
|
}
|
|
}
|
|
if (this.isLoadingChanged) {
|
|
Iterator<Player.EventListener> it2 = this.listeners.iterator();
|
|
while (it2.hasNext()) {
|
|
it2.next().onLoadingChanged(this.playbackInfo.isLoading);
|
|
}
|
|
}
|
|
if (this.playbackStateOrPlayWhenReadyChanged) {
|
|
Iterator<Player.EventListener> it3 = this.listeners.iterator();
|
|
while (it3.hasNext()) {
|
|
it3.next().onPlayerStateChanged(this.playWhenReady, this.playbackInfo.playbackState);
|
|
}
|
|
}
|
|
if (this.seekProcessed) {
|
|
Iterator<Player.EventListener> it4 = this.listeners.iterator();
|
|
while (it4.hasNext()) {
|
|
it4.next().onSeekProcessed();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|