mirror of
https://github.com/samsonjs/media.git
synced 2026-04-17 13:15:47 +00:00
Prepare for removal of period based ExoPlayer methods
- This change marks the methods that will be removed, and renames the Window methods to remove "Window" from their names. - The Window methods need to be made to work (rather than throw exceptions) when the timeline isn't set. Once that gets done in a subsequent CL, the deprecated methods will be removed. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130612979
This commit is contained in:
parent
1695e2ac48
commit
c009028dad
8 changed files with 105 additions and 70 deletions
|
|
@ -278,6 +278,7 @@ public interface ExoPlayer {
|
|||
*
|
||||
* @param positionMs The seek position.
|
||||
*/
|
||||
@Deprecated
|
||||
void seekInCurrentPeriod(long positionMs);
|
||||
|
||||
/**
|
||||
|
|
@ -289,6 +290,7 @@ public interface ExoPlayer {
|
|||
* @param periodIndex The index of the period whose associated default position should be seeked
|
||||
* to.
|
||||
*/
|
||||
@Deprecated
|
||||
void seekToDefaultPositionForPeriod(int periodIndex);
|
||||
|
||||
/**
|
||||
|
|
@ -297,14 +299,16 @@ public interface ExoPlayer {
|
|||
* @param periodIndex The index of the period.
|
||||
* @param positionMs The seek position relative to the start of the period.
|
||||
*/
|
||||
@Deprecated
|
||||
void seekInPeriod(int periodIndex, long positionMs);
|
||||
|
||||
/**
|
||||
* Seeks to a position specified in milliseconds in the current window.
|
||||
*
|
||||
* @param positionMs The seek position.
|
||||
* Seeks to the default position associated with the current window. The position can depend on
|
||||
* the type of source passed to {@link #setMediaSource(MediaSource)}. For live streams it will
|
||||
* typically be the live edge of the window. For other streams it will typically be the start of
|
||||
* the window.
|
||||
*/
|
||||
void seekInCurrentWindow(long positionMs);
|
||||
void seekToDefaultPosition();
|
||||
|
||||
/**
|
||||
* Seeks to the default position associated with the specified window. The position can depend on
|
||||
|
|
@ -315,15 +319,22 @@ public interface ExoPlayer {
|
|||
* @param windowIndex The index of the window whose associated default position should be seeked
|
||||
* to.
|
||||
*/
|
||||
void seekToDefaultPositionForWindow(int windowIndex);
|
||||
void seekToDefaultPosition(int windowIndex);
|
||||
|
||||
/**
|
||||
* Seeks to a position specified in milliseconds in the current window.
|
||||
*
|
||||
* @param positionMs The seek position.
|
||||
*/
|
||||
void seekTo(long positionMs);
|
||||
|
||||
/**
|
||||
* Seeks to a position specified in milliseconds in the specified seek window.
|
||||
*
|
||||
* @param seekWindowIndex The index of the seek window.
|
||||
* @param windowIndex The index of the window.
|
||||
* @param positionMs The seek position relative to the start of the window.
|
||||
*/
|
||||
void seekInWindow(int seekWindowIndex, long positionMs);
|
||||
void seekTo(int windowIndex, long positionMs);
|
||||
|
||||
/**
|
||||
* Stops playback. Use {@code setPlayWhenReady(false)} rather than this method if the intention
|
||||
|
|
@ -376,29 +387,34 @@ public interface ExoPlayer {
|
|||
/**
|
||||
* Returns the index of the current period.
|
||||
*/
|
||||
@Deprecated
|
||||
int getCurrentPeriodIndex();
|
||||
|
||||
/**
|
||||
* Returns the duration of the current period in milliseconds, or {@link #UNKNOWN_TIME} if the
|
||||
* duration is not known.
|
||||
*/
|
||||
@Deprecated
|
||||
long getCurrentPeriodDuration();
|
||||
|
||||
/**
|
||||
* Returns the playback position in the current period, in milliseconds.
|
||||
*/
|
||||
@Deprecated
|
||||
long getCurrentPositionInPeriod();
|
||||
|
||||
/**
|
||||
* Returns an estimate of the position in the current period up to which data is buffered, or
|
||||
* {@link #UNKNOWN_TIME} if no estimate is available.
|
||||
*/
|
||||
@Deprecated
|
||||
long getBufferedPositionInPeriod();
|
||||
|
||||
/**
|
||||
* Returns an estimate of the percentage in the current period up to which data is buffered, or 0
|
||||
* if no estimate is available.
|
||||
*/
|
||||
@Deprecated
|
||||
int getBufferedPercentageInPeriod();
|
||||
|
||||
// Window based.
|
||||
|
|
@ -413,29 +429,24 @@ public interface ExoPlayer {
|
|||
* Returns the duration of the current window in milliseconds, or {@link #UNKNOWN_TIME} if the
|
||||
* duration is not known.
|
||||
*/
|
||||
long getCurrentWindowDuration();
|
||||
long getDuration();
|
||||
|
||||
/**
|
||||
* Returns the playback position in the current seek window, in milliseconds, or
|
||||
* {@link #UNKNOWN_TIME} if the timeline is not set.
|
||||
*/
|
||||
long getCurrentPositionInWindow();
|
||||
long getCurrentPosition();
|
||||
|
||||
/**
|
||||
* Returns an estimate of the position in the current window up to which data is buffered, or
|
||||
* {@link #UNKNOWN_TIME} if no estimate is available.
|
||||
*/
|
||||
long getBufferedPositionInWindow();
|
||||
long getBufferedPosition();
|
||||
|
||||
/**
|
||||
* Returns an estimate of the percentage in the current window up to which data is buffered, or 0
|
||||
* if no estimate is available.
|
||||
*/
|
||||
int getBufferedPercentageInWindow();
|
||||
|
||||
// Misc methods
|
||||
|
||||
// TODO - Add a method/methods to expose this.
|
||||
// getBufferedPosition -> periodIndex,position
|
||||
int getBufferedPercentage();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,17 +151,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
public void seekInCurrentWindow(long positionMs) {
|
||||
Timeline timeline = getCurrentTimeline();
|
||||
if (timeline == null) {
|
||||
throw new IllegalArgumentException("Windows are not yet known");
|
||||
}
|
||||
int windowIndex = timeline.getPeriodWindowIndex(getCurrentPeriodIndex());
|
||||
seekInWindow(windowIndex, positionMs);
|
||||
public void seekToDefaultPosition() {
|
||||
seekToDefaultPosition(getCurrentWindowIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekToDefaultPositionForWindow(int windowIndex) {
|
||||
public void seekToDefaultPosition(int windowIndex) {
|
||||
if (timeline == null) {
|
||||
throw new IllegalArgumentException("Windows are not yet known");
|
||||
}
|
||||
|
|
@ -171,7 +166,17 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
public void seekInWindow(int windowIndex, long positionMs) {
|
||||
public void seekTo(long positionMs) {
|
||||
Timeline timeline = getCurrentTimeline();
|
||||
if (timeline == null) {
|
||||
throw new IllegalArgumentException("Windows are not yet known");
|
||||
}
|
||||
int windowIndex = timeline.getPeriodWindowIndex(getCurrentPeriodIndex());
|
||||
seekTo(windowIndex, positionMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekTo(int windowIndex, long positionMs) {
|
||||
if (timeline == null) {
|
||||
throw new IllegalArgumentException("Windows are not yet known");
|
||||
}
|
||||
|
|
@ -210,11 +215,13 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCurrentPeriodIndex() {
|
||||
return pendingSeekAcks == 0 ? playbackInfo.periodIndex : maskingPeriodIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getCurrentPeriodDuration() {
|
||||
if (timeline == null) {
|
||||
return UNKNOWN_TIME;
|
||||
|
|
@ -223,12 +230,14 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getCurrentPositionInPeriod() {
|
||||
return pendingSeekAcks > 0 ? maskingPositionMs
|
||||
: playbackInfo.positionUs == C.UNSET_TIME_US ? 0 : (playbackInfo.positionUs / 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getBufferedPositionInPeriod() {
|
||||
if (pendingSeekAcks == 0) {
|
||||
long bufferedPositionUs = playbackInfo.bufferedPositionUs;
|
||||
|
|
@ -239,6 +248,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getBufferedPercentageInPeriod() {
|
||||
if (timeline == null) {
|
||||
return 0;
|
||||
|
|
@ -258,7 +268,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentWindowDuration() {
|
||||
public long getDuration() {
|
||||
if (timeline == null) {
|
||||
return UNKNOWN_TIME;
|
||||
}
|
||||
|
|
@ -266,7 +276,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentPositionInWindow() {
|
||||
public long getCurrentPosition() {
|
||||
if (timeline == null) {
|
||||
return UNKNOWN_TIME;
|
||||
}
|
||||
|
|
@ -282,7 +292,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getBufferedPositionInWindow() {
|
||||
public long getBufferedPosition() {
|
||||
// TODO - Implement this properly.
|
||||
if (timeline == null) {
|
||||
return UNKNOWN_TIME;
|
||||
|
|
@ -294,16 +304,16 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
&& window.startTimeMs == 0 && window.durationMs == getCurrentPeriodDuration()) {
|
||||
return getBufferedPositionInPeriod();
|
||||
}
|
||||
return getCurrentPositionInWindow();
|
||||
return getCurrentPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferedPercentageInWindow() {
|
||||
public int getBufferedPercentage() {
|
||||
if (timeline == null) {
|
||||
return 0;
|
||||
}
|
||||
long bufferedPosition = getBufferedPositionInWindow();
|
||||
long duration = getCurrentWindowDuration();
|
||||
long bufferedPosition = getBufferedPosition();
|
||||
long duration = getDuration();
|
||||
return bufferedPosition == ExoPlayer.UNKNOWN_TIME || duration == ExoPlayer.UNKNOWN_TIME ? 0
|
||||
: (int) (duration == 0 ? 100 : (bufferedPosition * 100) / duration);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,33 +344,41 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void seekInCurrentPeriod(long positionMs) {
|
||||
player.seekInCurrentPeriod(positionMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void seekToDefaultPositionForPeriod(int periodIndex) {
|
||||
player.seekToDefaultPositionForPeriod(periodIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void seekInPeriod(int periodIndex, long positionMs) {
|
||||
player.seekInPeriod(periodIndex, positionMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekInCurrentWindow(long positionMs) {
|
||||
player.seekInCurrentWindow(positionMs);
|
||||
public void seekToDefaultPosition() {
|
||||
player.seekToDefaultPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekToDefaultPositionForWindow(int windowIndex) {
|
||||
player.seekToDefaultPositionForWindow(windowIndex);
|
||||
public void seekToDefaultPosition(int windowIndex) {
|
||||
player.seekToDefaultPosition(windowIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekInWindow(int windowIndex, long positionMs) {
|
||||
player.seekInWindow(windowIndex, positionMs);
|
||||
public void seekTo(long positionMs) {
|
||||
player.seekTo(positionMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekTo(int windowIndex, long positionMs) {
|
||||
player.seekTo(windowIndex, positionMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -394,26 +402,31 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCurrentPeriodIndex() {
|
||||
return player.getCurrentPeriodIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getCurrentPeriodDuration() {
|
||||
return player.getCurrentPeriodDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getCurrentPositionInPeriod() {
|
||||
return player.getCurrentPositionInPeriod();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getBufferedPositionInPeriod() {
|
||||
return player.getBufferedPositionInPeriod();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getBufferedPercentageInPeriod() {
|
||||
return player.getBufferedPercentageInPeriod();
|
||||
}
|
||||
|
|
@ -424,23 +437,23 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentWindowDuration() {
|
||||
return player.getCurrentWindowDuration();
|
||||
public long getDuration() {
|
||||
return player.getDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentPositionInWindow() {
|
||||
return player.getCurrentPositionInWindow();
|
||||
public long getCurrentPosition() {
|
||||
return player.getCurrentPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBufferedPositionInWindow() {
|
||||
return player.getBufferedPositionInWindow();
|
||||
public long getBufferedPosition() {
|
||||
return player.getBufferedPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferedPercentageInWindow() {
|
||||
return player.getBufferedPercentageInWindow();
|
||||
public int getBufferedPercentage() {
|
||||
return player.getBufferedPercentage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public final class DebugTextViewHelper implements Runnable, ExoPlayer.EventListe
|
|||
}
|
||||
|
||||
private void updateTextView() {
|
||||
textView.setText(getPlayerStateString() + getPlayerPeriodIndexString() + getVideoString()
|
||||
textView.setText(getPlayerStateString() + getPlayerWindowIndexString() + getVideoString()
|
||||
+ getAudioString());
|
||||
}
|
||||
|
||||
|
|
@ -104,8 +104,8 @@ public final class DebugTextViewHelper implements Runnable, ExoPlayer.EventListe
|
|||
return text;
|
||||
}
|
||||
|
||||
private String getPlayerPeriodIndexString() {
|
||||
return " period:" + player.getCurrentPeriodIndex();
|
||||
private String getPlayerWindowIndexString() {
|
||||
return " window:" + player.getCurrentWindowIndex();
|
||||
}
|
||||
|
||||
private String getVideoString() {
|
||||
|
|
|
|||
|
|
@ -18,21 +18,22 @@ package com.google.android.exoplayer2.ui;
|
|||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
|
||||
/**
|
||||
* An {@link OnClickListener} that can be passed to
|
||||
* {@link android.widget.MediaController#setPrevNextListeners(OnClickListener, OnClickListener)} to
|
||||
* make the controller's "previous" and "next" buttons visible and seek to the previous and next
|
||||
* periods in the timeline of the media being played.
|
||||
* windows in the timeline of the media being played.
|
||||
*/
|
||||
public class MediaControllerPrevNextClickListener implements OnClickListener {
|
||||
|
||||
/**
|
||||
* If a previous button is clicked the player is seeked to the start of the previous period if the
|
||||
* playback position in the current period is less than or equal to this constant (and if a
|
||||
* previous period exists). Else the player is seeked to the start of the current period.
|
||||
* If a previous button is clicked the player is seeked to the start of the previous window if the
|
||||
* playback position in the current window is less than or equal to this constant (and if a
|
||||
* previous window exists). Else the player is seeked to the start of the current window.
|
||||
*/
|
||||
private static final long MAX_POSITION_FOR_SEEK_TO_PREVIOUS_PERIOD = 3000;
|
||||
private static final long MAX_POSITION_FOR_SEEK_TO_PREVIOUS = 3000;
|
||||
|
||||
private final ExoPlayer player;
|
||||
private final boolean isNext;
|
||||
|
|
@ -52,16 +53,20 @@ public class MediaControllerPrevNextClickListener implements OnClickListener {
|
|||
if (currentWindowIndex == -1) {
|
||||
return;
|
||||
}
|
||||
Timeline timeline = player.getCurrentTimeline();
|
||||
if (isNext) {
|
||||
if (currentWindowIndex < player.getCurrentTimeline().getWindowCount() - 1) {
|
||||
player.seekToDefaultPositionForWindow(currentWindowIndex + 1);
|
||||
if (currentWindowIndex < timeline.getWindowCount() - 1) {
|
||||
player.seekToDefaultPosition(currentWindowIndex + 1);
|
||||
} else if (timeline.getWindow(currentWindowIndex).isDynamic) {
|
||||
// Seek to the live edge.
|
||||
player.seekToDefaultPosition();
|
||||
}
|
||||
} else {
|
||||
if (currentWindowIndex > 0
|
||||
&& player.getCurrentPositionInWindow() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS_PERIOD) {
|
||||
player.seekToDefaultPositionForWindow(currentWindowIndex - 1);
|
||||
&& player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS) {
|
||||
player.seekToDefaultPosition(currentWindowIndex - 1);
|
||||
} else {
|
||||
player.seekInWindow(currentWindowIndex, 0);
|
||||
player.seekTo(currentWindowIndex, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,18 +64,18 @@ public class PlayerControl implements MediaPlayerControl {
|
|||
|
||||
@Override
|
||||
public int getBufferPercentage() {
|
||||
return exoPlayer.getBufferedPercentageInWindow();
|
||||
return exoPlayer.getBufferedPercentage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentPosition() {
|
||||
long position = exoPlayer.getCurrentPositionInWindow();
|
||||
long position = exoPlayer.getCurrentPosition();
|
||||
return position == ExoPlayer.UNKNOWN_TIME ? 0 : (int) position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDuration() {
|
||||
long duration = exoPlayer.getCurrentWindowDuration();
|
||||
long duration = exoPlayer.getDuration();
|
||||
return duration == ExoPlayer.UNKNOWN_TIME ? 0 : (int) duration;
|
||||
}
|
||||
|
||||
|
|
@ -96,11 +96,7 @@ public class PlayerControl implements MediaPlayerControl {
|
|||
|
||||
@Override
|
||||
public void seekTo(int timeMillis) {
|
||||
int windowIndex = exoPlayer.getCurrentWindowIndex();
|
||||
if (windowIndex == -1) {
|
||||
return;
|
||||
}
|
||||
exoPlayer.seekInWindow(windowIndex, timeMillis);
|
||||
exoPlayer.seekTo(timeMillis);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public abstract class Action {
|
|||
protected abstract void doActionImpl(ExoPlayer player, MappingTrackSelector trackSelector);
|
||||
|
||||
/**
|
||||
* Calls {@link ExoPlayer#seekInCurrentPeriod(long)}.
|
||||
* Calls {@link ExoPlayer#seekTo(long)}.
|
||||
*/
|
||||
public static final class Seek extends Action {
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ public abstract class Action {
|
|||
|
||||
@Override
|
||||
protected void doActionImpl(ExoPlayer player, MappingTrackSelector trackSelector) {
|
||||
player.seekInCurrentPeriod(positionMs);
|
||||
player.seekTo(positionMs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public abstract class ExoHostedTest implements HostedTest, ExoPlayer.EventListen
|
|||
@Override
|
||||
public final void onStop() {
|
||||
actionHandler.removeCallbacksAndMessages(null);
|
||||
sourceDurationMs = player.getCurrentPeriodDuration();
|
||||
sourceDurationMs = player.getDuration();
|
||||
player.release();
|
||||
player = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue