Add BasePlayer to avoid code duplication for common convenience methods.
A lot of methods just forward to other methods and there is no conceivable way a player should implement it another way. Moving these methods to a base player class allows to remove duplicated code across our player implementations. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=215374192
This commit is contained in:
parent
4d9044d690
commit
bbd82cf5da
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.ext.cast;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.BasePlayer;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
@ -31,7 +32,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
|||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import com.google.android.gms.cast.CastStatusCodes;
|
import com.google.android.gms.cast.CastStatusCodes;
|
||||||
import com.google.android.gms.cast.MediaInfo;
|
import com.google.android.gms.cast.MediaInfo;
|
||||||
import com.google.android.gms.cast.MediaQueueItem;
|
import com.google.android.gms.cast.MediaQueueItem;
|
||||||
@ -62,7 +62,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
*
|
*
|
||||||
* <p>Methods should be called on the application's main thread.</p>
|
* <p>Methods should be called on the application's main thread.</p>
|
||||||
*/
|
*/
|
||||||
public final class CastPlayer implements Player {
|
public final class CastPlayer extends BasePlayer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener of changes in the cast session availability.
|
* Listener of changes in the cast session availability.
|
||||||
@ -95,7 +95,6 @@ public final class CastPlayer implements Player {
|
|||||||
private final CastContext castContext;
|
private final CastContext castContext;
|
||||||
// TODO: Allow custom implementations of CastTimelineTracker.
|
// TODO: Allow custom implementations of CastTimelineTracker.
|
||||||
private final CastTimelineTracker timelineTracker;
|
private final CastTimelineTracker timelineTracker;
|
||||||
private final Timeline.Window window;
|
|
||||||
private final Timeline.Period period;
|
private final Timeline.Period period;
|
||||||
|
|
||||||
private RemoteMediaClient remoteMediaClient;
|
private RemoteMediaClient remoteMediaClient;
|
||||||
@ -128,7 +127,6 @@ public final class CastPlayer implements Player {
|
|||||||
public CastPlayer(CastContext castContext) {
|
public CastPlayer(CastContext castContext) {
|
||||||
this.castContext = castContext;
|
this.castContext = castContext;
|
||||||
timelineTracker = new CastTimelineTracker();
|
timelineTracker = new CastTimelineTracker();
|
||||||
window = new Timeline.Window();
|
|
||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
statusListener = new StatusListener();
|
statusListener = new StatusListener();
|
||||||
seekResultCallback = new SeekResultCallback();
|
seekResultCallback = new SeekResultCallback();
|
||||||
@ -341,21 +339,6 @@ public final class CastPlayer implements Player {
|
|||||||
return playWhenReady;
|
return playWhenReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition() {
|
|
||||||
seekTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition(int windowIndex) {
|
|
||||||
seekTo(windowIndex, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekTo(long positionMs) {
|
|
||||||
seekTo(getCurrentWindowIndex(), positionMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int windowIndex, long positionMs) {
|
public void seekTo(int windowIndex, long positionMs) {
|
||||||
MediaStatus mediaStatus = getMediaStatus();
|
MediaStatus mediaStatus = getMediaStatus();
|
||||||
@ -392,11 +375,6 @@ public final class CastPlayer implements Player {
|
|||||||
return PlaybackParameters.DEFAULT;
|
return PlaybackParameters.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
stop(/* reset= */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(boolean reset) {
|
public void stop(boolean reset) {
|
||||||
playbackState = STATE_IDLE;
|
playbackState = STATE_IDLE;
|
||||||
@ -486,32 +464,11 @@ public final class CastPlayer implements Player {
|
|||||||
return pendingSeekWindowIndex != C.INDEX_UNSET ? pendingSeekWindowIndex : currentWindowIndex;
|
return pendingSeekWindowIndex != C.INDEX_UNSET ? pendingSeekWindowIndex : currentWindowIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextWindowIndex() {
|
|
||||||
return currentTimeline.isEmpty() ? C.INDEX_UNSET
|
|
||||||
: currentTimeline.getNextWindowIndex(getCurrentWindowIndex(), repeatMode, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPreviousWindowIndex() {
|
|
||||||
return currentTimeline.isEmpty() ? C.INDEX_UNSET
|
|
||||||
: currentTimeline.getPreviousWindowIndex(getCurrentWindowIndex(), repeatMode, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Object getCurrentTag() {
|
|
||||||
int windowIndex = getCurrentWindowIndex();
|
|
||||||
return windowIndex >= currentTimeline.getWindowCount()
|
|
||||||
? null
|
|
||||||
: currentTimeline.getWindow(windowIndex, window, /* setTag= */ true).tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Fill the cast timeline information with ProgressListener's duration updates.
|
// TODO: Fill the cast timeline information with ProgressListener's duration updates.
|
||||||
// See [Internal: b/65152553].
|
// See [Internal: b/65152553].
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() {
|
public long getDuration() {
|
||||||
return currentTimeline.isEmpty() ? C.TIME_UNSET
|
return getContentDuration();
|
||||||
: currentTimeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -528,15 +485,6 @@ public final class CastPlayer implements Player {
|
|||||||
return getCurrentPosition();
|
return getCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBufferedPercentage() {
|
|
||||||
long position = getBufferedPosition();
|
|
||||||
long duration = getDuration();
|
|
||||||
return position == C.TIME_UNSET || duration == C.TIME_UNSET
|
|
||||||
? 0
|
|
||||||
: duration == 0 ? 100 : Util.constrainValue((int) ((position * 100) / duration), 0, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTotalBufferedDuration() {
|
public long getTotalBufferedDuration() {
|
||||||
long bufferedPosition = getBufferedPosition();
|
long bufferedPosition = getBufferedPosition();
|
||||||
@ -546,18 +494,6 @@ public final class CastPlayer implements Player {
|
|||||||
: bufferedPosition - currentPosition;
|
: bufferedPosition - currentPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowDynamic() {
|
|
||||||
return !currentTimeline.isEmpty()
|
|
||||||
&& currentTimeline.getWindow(getCurrentWindowIndex(), window).isDynamic;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowSeekable() {
|
|
||||||
return !currentTimeline.isEmpty()
|
|
||||||
&& currentTimeline.getWindow(getCurrentWindowIndex(), window).isSeekable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayingAd() {
|
public boolean isPlayingAd() {
|
||||||
return false;
|
return false;
|
||||||
@ -573,11 +509,6 @@ public final class CastPlayer implements Player {
|
|||||||
return C.INDEX_UNSET;
|
return C.INDEX_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getContentDuration() {
|
|
||||||
return getDuration();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLoading() {
|
public boolean isLoading() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -26,7 +26,6 @@ import java.util.ArrayList;
|
|||||||
/* package */ final class FakePlayer extends StubExoPlayer {
|
/* package */ final class FakePlayer extends StubExoPlayer {
|
||||||
|
|
||||||
private final ArrayList<Player.EventListener> listeners;
|
private final ArrayList<Player.EventListener> listeners;
|
||||||
private final Timeline.Window window;
|
|
||||||
private final Timeline.Period period;
|
private final Timeline.Period period;
|
||||||
private final Timeline timeline;
|
private final Timeline timeline;
|
||||||
|
|
||||||
@ -41,7 +40,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public FakePlayer() {
|
public FakePlayer() {
|
||||||
listeners = new ArrayList<>();
|
listeners = new ArrayList<>();
|
||||||
window = new Timeline.Window();
|
|
||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
state = Player.STATE_IDLE;
|
state = Player.STATE_IDLE;
|
||||||
playWhenReady = true;
|
playWhenReady = true;
|
||||||
@ -151,16 +149,6 @@ import java.util.ArrayList;
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextWindowIndex() {
|
|
||||||
return C.INDEX_UNSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPreviousWindowIndex() {
|
|
||||||
return C.INDEX_UNSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() {
|
public long getDuration() {
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
|
@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
||||||
|
/** Abstract base {@link Player} which implements common implementation independent methods. */
|
||||||
|
public abstract class BasePlayer implements Player {
|
||||||
|
|
||||||
|
protected final Timeline.Window window;
|
||||||
|
|
||||||
|
public BasePlayer() {
|
||||||
|
window = new Timeline.Window();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void seekToDefaultPosition() {
|
||||||
|
seekToDefaultPosition(getCurrentWindowIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void seekToDefaultPosition(int windowIndex) {
|
||||||
|
seekTo(windowIndex, /* positionMs= */ C.TIME_UNSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void seekTo(long positionMs) {
|
||||||
|
seekTo(getCurrentWindowIndex(), positionMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean hasPrevious() {
|
||||||
|
return getPreviousWindowIndex() != C.INDEX_UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void previous() {
|
||||||
|
int previousWindowIndex = getPreviousWindowIndex();
|
||||||
|
if (previousWindowIndex != C.INDEX_UNSET) {
|
||||||
|
seekToDefaultPosition(previousWindowIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean hasNext() {
|
||||||
|
return getNextWindowIndex() != C.INDEX_UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void next() {
|
||||||
|
int nextWindowIndex = getPreviousWindowIndex();
|
||||||
|
if (nextWindowIndex != C.INDEX_UNSET) {
|
||||||
|
seekToDefaultPosition(nextWindowIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void stop() {
|
||||||
|
stop(/* reset= */ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getNextWindowIndex() {
|
||||||
|
Timeline timeline = getCurrentTimeline();
|
||||||
|
return timeline.isEmpty()
|
||||||
|
? C.INDEX_UNSET
|
||||||
|
: timeline.getNextWindowIndex(
|
||||||
|
getCurrentWindowIndex(), getRepeatMode(), getShuffleModeEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getPreviousWindowIndex() {
|
||||||
|
Timeline timeline = getCurrentTimeline();
|
||||||
|
return timeline.isEmpty()
|
||||||
|
? C.INDEX_UNSET
|
||||||
|
: timeline.getPreviousWindowIndex(
|
||||||
|
getCurrentWindowIndex(), getRepeatMode(), getShuffleModeEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public final Object getCurrentTag() {
|
||||||
|
int windowIndex = getCurrentWindowIndex();
|
||||||
|
Timeline timeline = getCurrentTimeline();
|
||||||
|
return windowIndex >= timeline.getWindowCount()
|
||||||
|
? null
|
||||||
|
: timeline.getWindow(windowIndex, window, /* setTag= */ true).tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getBufferedPercentage() {
|
||||||
|
long position = getBufferedPosition();
|
||||||
|
long duration = getDuration();
|
||||||
|
return position == C.TIME_UNSET || duration == C.TIME_UNSET
|
||||||
|
? 0
|
||||||
|
: duration == 0 ? 100 : Util.constrainValue((int) ((position * 100) / duration), 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean isCurrentWindowDynamic() {
|
||||||
|
Timeline timeline = getCurrentTimeline();
|
||||||
|
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isDynamic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean isCurrentWindowSeekable() {
|
||||||
|
Timeline timeline = getCurrentTimeline();
|
||||||
|
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isSeekable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final long getContentDuration() {
|
||||||
|
Timeline timeline = getCurrentTimeline();
|
||||||
|
return timeline.isEmpty()
|
||||||
|
? C.TIME_UNSET
|
||||||
|
: timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
|
||||||
|
}
|
||||||
|
}
|
@ -40,10 +40,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
/**
|
/** An {@link ExoPlayer} implementation. Instances can be obtained from {@link ExoPlayerFactory}. */
|
||||||
* An {@link ExoPlayer} implementation. Instances can be obtained from {@link ExoPlayerFactory}.
|
/* package */ final class ExoPlayerImpl extends BasePlayer implements ExoPlayer {
|
||||||
*/
|
|
||||||
/* package */ final class ExoPlayerImpl implements ExoPlayer {
|
|
||||||
|
|
||||||
private static final String TAG = "ExoPlayerImpl";
|
private static final String TAG = "ExoPlayerImpl";
|
||||||
|
|
||||||
@ -61,7 +59,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
private final ExoPlayerImplInternal internalPlayer;
|
private final ExoPlayerImplInternal internalPlayer;
|
||||||
private final Handler internalPlayerHandler;
|
private final Handler internalPlayerHandler;
|
||||||
private final CopyOnWriteArraySet<Player.EventListener> listeners;
|
private final CopyOnWriteArraySet<Player.EventListener> listeners;
|
||||||
private final Timeline.Window window;
|
|
||||||
private final Timeline.Period period;
|
private final Timeline.Period period;
|
||||||
private final ArrayDeque<PlaybackInfoUpdate> pendingPlaybackInfoUpdates;
|
private final ArrayDeque<PlaybackInfoUpdate> pendingPlaybackInfoUpdates;
|
||||||
|
|
||||||
@ -118,7 +115,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
new RendererConfiguration[renderers.length],
|
new RendererConfiguration[renderers.length],
|
||||||
new TrackSelection[renderers.length],
|
new TrackSelection[renderers.length],
|
||||||
null);
|
null);
|
||||||
window = new Timeline.Window();
|
|
||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
playbackParameters = PlaybackParameters.DEFAULT;
|
playbackParameters = PlaybackParameters.DEFAULT;
|
||||||
seekParameters = SeekParameters.DEFAULT;
|
seekParameters = SeekParameters.DEFAULT;
|
||||||
@ -293,21 +289,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
return playbackInfo.isLoading;
|
return playbackInfo.isLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition() {
|
|
||||||
seekToDefaultPosition(getCurrentWindowIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition(int windowIndex) {
|
|
||||||
seekTo(windowIndex, C.TIME_UNSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekTo(long positionMs) {
|
|
||||||
seekTo(getCurrentWindowIndex(), positionMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int windowIndex, long positionMs) {
|
public void seekTo(int windowIndex, long positionMs) {
|
||||||
Timeline timeline = playbackInfo.timeline;
|
Timeline timeline = playbackInfo.timeline;
|
||||||
@ -377,19 +358,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
return seekParameters;
|
return seekParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Object getCurrentTag() {
|
|
||||||
int windowIndex = getCurrentWindowIndex();
|
|
||||||
return windowIndex >= playbackInfo.timeline.getWindowCount()
|
|
||||||
? null
|
|
||||||
: playbackInfo.timeline.getWindow(windowIndex, window, /* setTag= */ true).tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
stop(/* reset= */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(boolean reset) {
|
public void stop(boolean reset) {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
@ -494,20 +462,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextWindowIndex() {
|
|
||||||
Timeline timeline = playbackInfo.timeline;
|
|
||||||
return timeline.isEmpty() ? C.INDEX_UNSET
|
|
||||||
: timeline.getNextWindowIndex(getCurrentWindowIndex(), repeatMode, shuffleModeEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPreviousWindowIndex() {
|
|
||||||
Timeline timeline = playbackInfo.timeline;
|
|
||||||
return timeline.isEmpty() ? C.INDEX_UNSET
|
|
||||||
: timeline.getPreviousWindowIndex(getCurrentWindowIndex(), repeatMode, shuffleModeEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() {
|
public long getDuration() {
|
||||||
if (isPlayingAd()) {
|
if (isPlayingAd()) {
|
||||||
@ -540,32 +494,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
return getContentBufferedPosition();
|
return getContentBufferedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBufferedPercentage() {
|
|
||||||
long position = getBufferedPosition();
|
|
||||||
long duration = getDuration();
|
|
||||||
return position == C.TIME_UNSET || duration == C.TIME_UNSET
|
|
||||||
? 0
|
|
||||||
: (duration == 0 ? 100 : Util.constrainValue((int) ((position * 100) / duration), 0, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTotalBufferedDuration() {
|
public long getTotalBufferedDuration() {
|
||||||
return Math.max(0, C.usToMs(playbackInfo.totalBufferedDurationUs));
|
return Math.max(0, C.usToMs(playbackInfo.totalBufferedDurationUs));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowDynamic() {
|
|
||||||
Timeline timeline = playbackInfo.timeline;
|
|
||||||
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isDynamic;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowSeekable() {
|
|
||||||
Timeline timeline = playbackInfo.timeline;
|
|
||||||
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isSeekable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayingAd() {
|
public boolean isPlayingAd() {
|
||||||
return !shouldMaskPosition() && playbackInfo.periodId.isAd();
|
return !shouldMaskPosition() && playbackInfo.periodId.isAd();
|
||||||
@ -581,13 +514,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
return isPlayingAd() ? playbackInfo.periodId.adIndexInAdGroup : C.INDEX_UNSET;
|
return isPlayingAd() ? playbackInfo.periodId.adIndexInAdGroup : C.INDEX_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getContentDuration() {
|
|
||||||
return playbackInfo.timeline.isEmpty()
|
|
||||||
? C.TIME_UNSET
|
|
||||||
: playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentPosition() {
|
public long getContentPosition() {
|
||||||
if (isPlayingAd()) {
|
if (isPlayingAd()) {
|
||||||
|
@ -64,7 +64,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
* be obtained from {@link ExoPlayerFactory}.
|
* be obtained from {@link ExoPlayerFactory}.
|
||||||
*/
|
*/
|
||||||
@TargetApi(16)
|
@TargetApi(16)
|
||||||
public class SimpleExoPlayer
|
public class SimpleExoPlayer extends BasePlayer
|
||||||
implements ExoPlayer, Player.AudioComponent, Player.VideoComponent, Player.TextComponent {
|
implements ExoPlayer, Player.AudioComponent, Player.VideoComponent, Player.TextComponent {
|
||||||
|
|
||||||
/** @deprecated Use {@link com.google.android.exoplayer2.video.VideoListener}. */
|
/** @deprecated Use {@link com.google.android.exoplayer2.video.VideoListener}. */
|
||||||
@ -927,27 +927,6 @@ public class SimpleExoPlayer
|
|||||||
return player.isLoading();
|
return player.isLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
analyticsCollector.notifySeekStarted();
|
|
||||||
player.seekToDefaultPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition(int windowIndex) {
|
|
||||||
verifyApplicationThread();
|
|
||||||
analyticsCollector.notifySeekStarted();
|
|
||||||
player.seekToDefaultPosition(windowIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekTo(long positionMs) {
|
|
||||||
verifyApplicationThread();
|
|
||||||
analyticsCollector.notifySeekStarted();
|
|
||||||
player.seekTo(positionMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int windowIndex, long positionMs) {
|
public void seekTo(int windowIndex, long positionMs) {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
@ -979,17 +958,6 @@ public class SimpleExoPlayer
|
|||||||
return player.getSeekParameters();
|
return player.getSeekParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Object getCurrentTag() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.getCurrentTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
stop(/* reset= */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(boolean reset) {
|
public void stop(boolean reset) {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
@ -1092,18 +1060,6 @@ public class SimpleExoPlayer
|
|||||||
return player.getCurrentWindowIndex();
|
return player.getCurrentWindowIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextWindowIndex() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.getNextWindowIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPreviousWindowIndex() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.getPreviousWindowIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() {
|
public long getDuration() {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
@ -1122,30 +1078,12 @@ public class SimpleExoPlayer
|
|||||||
return player.getBufferedPosition();
|
return player.getBufferedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBufferedPercentage() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.getBufferedPercentage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTotalBufferedDuration() {
|
public long getTotalBufferedDuration() {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
return player.getTotalBufferedDuration();
|
return player.getTotalBufferedDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowDynamic() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.isCurrentWindowDynamic();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowSeekable() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.isCurrentWindowSeekable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayingAd() {
|
public boolean isPlayingAd() {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
@ -1164,12 +1102,6 @@ public class SimpleExoPlayer
|
|||||||
return player.getCurrentAdIndexInAdGroup();
|
return player.getCurrentAdIndexInAdGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getContentDuration() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
return player.getContentDuration();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentPosition() {
|
public long getContentPosition() {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.support.annotation.Nullable;
|
import com.google.android.exoplayer2.BasePlayer;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.ExoPlayer;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
@ -32,7 +32,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
|||||||
* An abstract {@link ExoPlayer} implementation that throws {@link UnsupportedOperationException}
|
* An abstract {@link ExoPlayer} implementation that throws {@link UnsupportedOperationException}
|
||||||
* from every method.
|
* from every method.
|
||||||
*/
|
*/
|
||||||
public abstract class StubExoPlayer implements ExoPlayer {
|
public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AudioComponent getAudioComponent() {
|
public AudioComponent getAudioComponent() {
|
||||||
@ -129,21 +129,6 @@ public abstract class StubExoPlayer implements ExoPlayer {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekToDefaultPosition(int windowIndex) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void seekTo(long positionMs) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int windowIndex, long positionMs) {
|
public void seekTo(int windowIndex, long positionMs) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@ -169,16 +154,6 @@ public abstract class StubExoPlayer implements ExoPlayer {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Object getCurrentTag() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(boolean resetStateAndPosition) {
|
public void stop(boolean resetStateAndPosition) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@ -248,16 +223,6 @@ public abstract class StubExoPlayer implements ExoPlayer {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextWindowIndex() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPreviousWindowIndex() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() {
|
public long getDuration() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@ -273,26 +238,11 @@ public abstract class StubExoPlayer implements ExoPlayer {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBufferedPercentage() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTotalBufferedDuration() {
|
public long getTotalBufferedDuration() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowDynamic() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCurrentWindowSeekable() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayingAd() {
|
public boolean isPlayingAd() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@ -308,11 +258,6 @@ public abstract class StubExoPlayer implements ExoPlayer {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getContentDuration() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentPosition() {
|
public long getContentPosition() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user