mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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.
|
* @param positionMs The seek position.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void seekInCurrentPeriod(long positionMs);
|
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
|
* @param periodIndex The index of the period whose associated default position should be seeked
|
||||||
* to.
|
* to.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void seekToDefaultPositionForPeriod(int periodIndex);
|
void seekToDefaultPositionForPeriod(int periodIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -297,14 +299,16 @@ public interface ExoPlayer {
|
||||||
* @param periodIndex The index of the period.
|
* @param periodIndex The index of the period.
|
||||||
* @param positionMs The seek position relative to the start of the period.
|
* @param positionMs The seek position relative to the start of the period.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void seekInPeriod(int periodIndex, long positionMs);
|
void seekInPeriod(int periodIndex, long positionMs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seeks to a position specified in milliseconds in the current window.
|
* 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
|
||||||
* @param positionMs The seek position.
|
* 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
|
* 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
|
* @param windowIndex The index of the window whose associated default position should be seeked
|
||||||
* to.
|
* 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.
|
* 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.
|
* @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
|
* 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.
|
* Returns the index of the current period.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
int getCurrentPeriodIndex();
|
int getCurrentPeriodIndex();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the duration of the current period in milliseconds, or {@link #UNKNOWN_TIME} if the
|
* Returns the duration of the current period in milliseconds, or {@link #UNKNOWN_TIME} if the
|
||||||
* duration is not known.
|
* duration is not known.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
long getCurrentPeriodDuration();
|
long getCurrentPeriodDuration();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the playback position in the current period, in milliseconds.
|
* Returns the playback position in the current period, in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
long getCurrentPositionInPeriod();
|
long getCurrentPositionInPeriod();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an estimate of the position in the current period up to which data is buffered, or
|
* 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.
|
* {@link #UNKNOWN_TIME} if no estimate is available.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
long getBufferedPositionInPeriod();
|
long getBufferedPositionInPeriod();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an estimate of the percentage in the current period up to which data is buffered, or 0
|
* Returns an estimate of the percentage in the current period up to which data is buffered, or 0
|
||||||
* if no estimate is available.
|
* if no estimate is available.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
int getBufferedPercentageInPeriod();
|
int getBufferedPercentageInPeriod();
|
||||||
|
|
||||||
// Window based.
|
// Window based.
|
||||||
|
|
@ -413,29 +429,24 @@ public interface ExoPlayer {
|
||||||
* Returns the duration of the current window in milliseconds, or {@link #UNKNOWN_TIME} if the
|
* Returns the duration of the current window in milliseconds, or {@link #UNKNOWN_TIME} if the
|
||||||
* duration is not known.
|
* duration is not known.
|
||||||
*/
|
*/
|
||||||
long getCurrentWindowDuration();
|
long getDuration();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the playback position in the current seek window, in milliseconds, or
|
* Returns the playback position in the current seek window, in milliseconds, or
|
||||||
* {@link #UNKNOWN_TIME} if the timeline is not set.
|
* {@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
|
* 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.
|
* {@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
|
* Returns an estimate of the percentage in the current window up to which data is buffered, or 0
|
||||||
* if no estimate is available.
|
* if no estimate is available.
|
||||||
*/
|
*/
|
||||||
int getBufferedPercentageInWindow();
|
int getBufferedPercentage();
|
||||||
|
|
||||||
// Misc methods
|
|
||||||
|
|
||||||
// TODO - Add a method/methods to expose this.
|
|
||||||
// getBufferedPosition -> periodIndex,position
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,17 +151,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekInCurrentWindow(long positionMs) {
|
public void seekToDefaultPosition() {
|
||||||
Timeline timeline = getCurrentTimeline();
|
seekToDefaultPosition(getCurrentWindowIndex());
|
||||||
if (timeline == null) {
|
|
||||||
throw new IllegalArgumentException("Windows are not yet known");
|
|
||||||
}
|
|
||||||
int windowIndex = timeline.getPeriodWindowIndex(getCurrentPeriodIndex());
|
|
||||||
seekInWindow(windowIndex, positionMs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekToDefaultPositionForWindow(int windowIndex) {
|
public void seekToDefaultPosition(int windowIndex) {
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
throw new IllegalArgumentException("Windows are not yet known");
|
throw new IllegalArgumentException("Windows are not yet known");
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +166,17 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (timeline == null) {
|
||||||
throw new IllegalArgumentException("Windows are not yet known");
|
throw new IllegalArgumentException("Windows are not yet known");
|
||||||
}
|
}
|
||||||
|
|
@ -210,11 +215,13 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public int getCurrentPeriodIndex() {
|
public int getCurrentPeriodIndex() {
|
||||||
return pendingSeekAcks == 0 ? playbackInfo.periodIndex : maskingPeriodIndex;
|
return pendingSeekAcks == 0 ? playbackInfo.periodIndex : maskingPeriodIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public long getCurrentPeriodDuration() {
|
public long getCurrentPeriodDuration() {
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
return UNKNOWN_TIME;
|
return UNKNOWN_TIME;
|
||||||
|
|
@ -223,12 +230,14 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public long getCurrentPositionInPeriod() {
|
public long getCurrentPositionInPeriod() {
|
||||||
return pendingSeekAcks > 0 ? maskingPositionMs
|
return pendingSeekAcks > 0 ? maskingPositionMs
|
||||||
: playbackInfo.positionUs == C.UNSET_TIME_US ? 0 : (playbackInfo.positionUs / 1000);
|
: playbackInfo.positionUs == C.UNSET_TIME_US ? 0 : (playbackInfo.positionUs / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public long getBufferedPositionInPeriod() {
|
public long getBufferedPositionInPeriod() {
|
||||||
if (pendingSeekAcks == 0) {
|
if (pendingSeekAcks == 0) {
|
||||||
long bufferedPositionUs = playbackInfo.bufferedPositionUs;
|
long bufferedPositionUs = playbackInfo.bufferedPositionUs;
|
||||||
|
|
@ -239,6 +248,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public int getBufferedPercentageInPeriod() {
|
public int getBufferedPercentageInPeriod() {
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -258,7 +268,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentWindowDuration() {
|
public long getDuration() {
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
return UNKNOWN_TIME;
|
return UNKNOWN_TIME;
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +276,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentPositionInWindow() {
|
public long getCurrentPosition() {
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
return UNKNOWN_TIME;
|
return UNKNOWN_TIME;
|
||||||
}
|
}
|
||||||
|
|
@ -282,7 +292,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getBufferedPositionInWindow() {
|
public long getBufferedPosition() {
|
||||||
// TODO - Implement this properly.
|
// TODO - Implement this properly.
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
return UNKNOWN_TIME;
|
return UNKNOWN_TIME;
|
||||||
|
|
@ -294,16 +304,16 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
&& window.startTimeMs == 0 && window.durationMs == getCurrentPeriodDuration()) {
|
&& window.startTimeMs == 0 && window.durationMs == getCurrentPeriodDuration()) {
|
||||||
return getBufferedPositionInPeriod();
|
return getBufferedPositionInPeriod();
|
||||||
}
|
}
|
||||||
return getCurrentPositionInWindow();
|
return getCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBufferedPercentageInWindow() {
|
public int getBufferedPercentage() {
|
||||||
if (timeline == null) {
|
if (timeline == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
long bufferedPosition = getBufferedPositionInWindow();
|
long bufferedPosition = getBufferedPosition();
|
||||||
long duration = getCurrentWindowDuration();
|
long duration = getDuration();
|
||||||
return bufferedPosition == ExoPlayer.UNKNOWN_TIME || duration == ExoPlayer.UNKNOWN_TIME ? 0
|
return bufferedPosition == ExoPlayer.UNKNOWN_TIME || duration == ExoPlayer.UNKNOWN_TIME ? 0
|
||||||
: (int) (duration == 0 ? 100 : (bufferedPosition * 100) / duration);
|
: (int) (duration == 0 ? 100 : (bufferedPosition * 100) / duration);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -344,33 +344,41 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void seekInCurrentPeriod(long positionMs) {
|
public void seekInCurrentPeriod(long positionMs) {
|
||||||
player.seekInCurrentPeriod(positionMs);
|
player.seekInCurrentPeriod(positionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void seekToDefaultPositionForPeriod(int periodIndex) {
|
public void seekToDefaultPositionForPeriod(int periodIndex) {
|
||||||
player.seekToDefaultPositionForPeriod(periodIndex);
|
player.seekToDefaultPositionForPeriod(periodIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void seekInPeriod(int periodIndex, long positionMs) {
|
public void seekInPeriod(int periodIndex, long positionMs) {
|
||||||
player.seekInPeriod(periodIndex, positionMs);
|
player.seekInPeriod(periodIndex, positionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekInCurrentWindow(long positionMs) {
|
public void seekToDefaultPosition() {
|
||||||
player.seekInCurrentWindow(positionMs);
|
player.seekToDefaultPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekToDefaultPositionForWindow(int windowIndex) {
|
public void seekToDefaultPosition(int windowIndex) {
|
||||||
player.seekToDefaultPositionForWindow(windowIndex);
|
player.seekToDefaultPosition(windowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekInWindow(int windowIndex, long positionMs) {
|
public void seekTo(long positionMs) {
|
||||||
player.seekInWindow(windowIndex, positionMs);
|
player.seekTo(positionMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void seekTo(int windowIndex, long positionMs) {
|
||||||
|
player.seekTo(windowIndex, positionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -394,26 +402,31 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public int getCurrentPeriodIndex() {
|
public int getCurrentPeriodIndex() {
|
||||||
return player.getCurrentPeriodIndex();
|
return player.getCurrentPeriodIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public long getCurrentPeriodDuration() {
|
public long getCurrentPeriodDuration() {
|
||||||
return player.getCurrentPeriodDuration();
|
return player.getCurrentPeriodDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public long getCurrentPositionInPeriod() {
|
public long getCurrentPositionInPeriod() {
|
||||||
return player.getCurrentPositionInPeriod();
|
return player.getCurrentPositionInPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public long getBufferedPositionInPeriod() {
|
public long getBufferedPositionInPeriod() {
|
||||||
return player.getBufferedPositionInPeriod();
|
return player.getBufferedPositionInPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public int getBufferedPercentageInPeriod() {
|
public int getBufferedPercentageInPeriod() {
|
||||||
return player.getBufferedPercentageInPeriod();
|
return player.getBufferedPercentageInPeriod();
|
||||||
}
|
}
|
||||||
|
|
@ -424,23 +437,23 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentWindowDuration() {
|
public long getDuration() {
|
||||||
return player.getCurrentWindowDuration();
|
return player.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentPositionInWindow() {
|
public long getCurrentPosition() {
|
||||||
return player.getCurrentPositionInWindow();
|
return player.getCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getBufferedPositionInWindow() {
|
public long getBufferedPosition() {
|
||||||
return player.getBufferedPositionInWindow();
|
return player.getBufferedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBufferedPercentageInWindow() {
|
public int getBufferedPercentage() {
|
||||||
return player.getBufferedPercentageInWindow();
|
return player.getBufferedPercentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ public final class DebugTextViewHelper implements Runnable, ExoPlayer.EventListe
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTextView() {
|
private void updateTextView() {
|
||||||
textView.setText(getPlayerStateString() + getPlayerPeriodIndexString() + getVideoString()
|
textView.setText(getPlayerStateString() + getPlayerWindowIndexString() + getVideoString()
|
||||||
+ getAudioString());
|
+ getAudioString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,8 +104,8 @@ public final class DebugTextViewHelper implements Runnable, ExoPlayer.EventListe
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlayerPeriodIndexString() {
|
private String getPlayerWindowIndexString() {
|
||||||
return " period:" + player.getCurrentPeriodIndex();
|
return " window:" + player.getCurrentWindowIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getVideoString() {
|
private String getVideoString() {
|
||||||
|
|
|
||||||
|
|
@ -18,21 +18,22 @@ package com.google.android.exoplayer2.ui;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.ExoPlayer;
|
||||||
|
import com.google.android.exoplayer2.Timeline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OnClickListener} that can be passed to
|
* An {@link OnClickListener} that can be passed to
|
||||||
* {@link android.widget.MediaController#setPrevNextListeners(OnClickListener, OnClickListener)} 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
|
* 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 {
|
public class MediaControllerPrevNextClickListener implements OnClickListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a previous button is clicked the player is seeked to the start of the previous period if the
|
* If a previous button is clicked the player is seeked to the start of the previous window if the
|
||||||
* playback position in the current period is less than or equal to this constant (and if a
|
* playback position in the current window 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.
|
* 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 ExoPlayer player;
|
||||||
private final boolean isNext;
|
private final boolean isNext;
|
||||||
|
|
@ -52,16 +53,20 @@ public class MediaControllerPrevNextClickListener implements OnClickListener {
|
||||||
if (currentWindowIndex == -1) {
|
if (currentWindowIndex == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Timeline timeline = player.getCurrentTimeline();
|
||||||
if (isNext) {
|
if (isNext) {
|
||||||
if (currentWindowIndex < player.getCurrentTimeline().getWindowCount() - 1) {
|
if (currentWindowIndex < timeline.getWindowCount() - 1) {
|
||||||
player.seekToDefaultPositionForWindow(currentWindowIndex + 1);
|
player.seekToDefaultPosition(currentWindowIndex + 1);
|
||||||
|
} else if (timeline.getWindow(currentWindowIndex).isDynamic) {
|
||||||
|
// Seek to the live edge.
|
||||||
|
player.seekToDefaultPosition();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (currentWindowIndex > 0
|
if (currentWindowIndex > 0
|
||||||
&& player.getCurrentPositionInWindow() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS_PERIOD) {
|
&& player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS) {
|
||||||
player.seekToDefaultPositionForWindow(currentWindowIndex - 1);
|
player.seekToDefaultPosition(currentWindowIndex - 1);
|
||||||
} else {
|
} else {
|
||||||
player.seekInWindow(currentWindowIndex, 0);
|
player.seekTo(currentWindowIndex, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,18 +64,18 @@ public class PlayerControl implements MediaPlayerControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBufferPercentage() {
|
public int getBufferPercentage() {
|
||||||
return exoPlayer.getBufferedPercentageInWindow();
|
return exoPlayer.getBufferedPercentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCurrentPosition() {
|
public int getCurrentPosition() {
|
||||||
long position = exoPlayer.getCurrentPositionInWindow();
|
long position = exoPlayer.getCurrentPosition();
|
||||||
return position == ExoPlayer.UNKNOWN_TIME ? 0 : (int) position;
|
return position == ExoPlayer.UNKNOWN_TIME ? 0 : (int) position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
long duration = exoPlayer.getCurrentWindowDuration();
|
long duration = exoPlayer.getDuration();
|
||||||
return duration == ExoPlayer.UNKNOWN_TIME ? 0 : (int) duration;
|
return duration == ExoPlayer.UNKNOWN_TIME ? 0 : (int) duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,11 +96,7 @@ public class PlayerControl implements MediaPlayerControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int timeMillis) {
|
public void seekTo(int timeMillis) {
|
||||||
int windowIndex = exoPlayer.getCurrentWindowIndex();
|
exoPlayer.seekTo(timeMillis);
|
||||||
if (windowIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
exoPlayer.seekInWindow(windowIndex, timeMillis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public abstract class Action {
|
||||||
protected abstract void doActionImpl(ExoPlayer player, MappingTrackSelector trackSelector);
|
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 {
|
public static final class Seek extends Action {
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ public abstract class Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doActionImpl(ExoPlayer player, MappingTrackSelector trackSelector) {
|
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
|
@Override
|
||||||
public final void onStop() {
|
public final void onStop() {
|
||||||
actionHandler.removeCallbacksAndMessages(null);
|
actionHandler.removeCallbacksAndMessages(null);
|
||||||
sourceDurationMs = player.getCurrentPeriodDuration();
|
sourceDurationMs = player.getDuration();
|
||||||
player.release();
|
player.release();
|
||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue