mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
bufferedPositionUs cannot be UNSET.
Also do some naming cleanup + do ms->us seek conversion in ExoPlayerImpl, since that's where we now do all the conversions coming out of the player. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125662973
This commit is contained in:
parent
e1d3c932fa
commit
79cbd390ab
2 changed files with 26 additions and 27 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer;
|
package com.google.android.exoplayer;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer.ExoPlayerImplInternal.PlaybackInfo;
|
||||||
import com.google.android.exoplayer.util.Assertions;
|
import com.google.android.exoplayer.util.Assertions;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
|
@ -42,12 +43,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
private int pendingSetSourceProviderAndSeekAcks;
|
private int pendingSetSourceProviderAndSeekAcks;
|
||||||
|
|
||||||
// Playback information when there is no pending seek/set source operation.
|
// Playback information when there is no pending seek/set source operation.
|
||||||
private ExoPlayerImplInternal.PlaybackInfo playbackInfo;
|
private PlaybackInfo playbackInfo;
|
||||||
|
|
||||||
// Playback information when there is a pending seek/set source operation.
|
// Playback information when there is a pending seek/set source operation.
|
||||||
private int sourceIndex;
|
private int maskingSourceIndex;
|
||||||
private long position;
|
private long maskingPositionMs;
|
||||||
private long duration;
|
private long maskingDurationMs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance. Must be invoked from a thread that has an associated {@link Looper}.
|
* Constructs an instance. Must be invoked from a thread that has an associated {@link Looper}.
|
||||||
|
|
@ -102,14 +103,14 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSourceProvider(SampleSourceProvider sourceProvider) {
|
public void setSourceProvider(SampleSourceProvider sourceProvider) {
|
||||||
duration = ExoPlayer.UNKNOWN_TIME;
|
maskingSourceIndex = 0;
|
||||||
position = 0;
|
maskingPositionMs = 0;
|
||||||
sourceIndex = 0;
|
maskingDurationMs = ExoPlayer.UNKNOWN_TIME;
|
||||||
|
|
||||||
pendingSetSourceProviderAndSeekAcks++;
|
pendingSetSourceProviderAndSeekAcks++;
|
||||||
internalPlayer.setSourceProvider(sourceProvider);
|
internalPlayer.setSourceProvider(sourceProvider);
|
||||||
for (EventListener listener : listeners) {
|
for (EventListener listener : listeners) {
|
||||||
listener.onPositionDiscontinuity(sourceIndex, position);
|
listener.onPositionDiscontinuity(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,14 +143,15 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int sourceIndex, long positionMs) {
|
public void seekTo(int sourceIndex, long positionMs) {
|
||||||
duration = sourceIndex == getCurrentSourceIndex() ? getDuration() : ExoPlayer.UNKNOWN_TIME;
|
boolean sourceChanging = sourceIndex != getCurrentSourceIndex();
|
||||||
position = positionMs;
|
maskingSourceIndex = sourceIndex;
|
||||||
this.sourceIndex = sourceIndex;
|
maskingPositionMs = positionMs;
|
||||||
|
maskingDurationMs = sourceChanging ? ExoPlayer.UNKNOWN_TIME : getDuration();
|
||||||
|
|
||||||
pendingSetSourceProviderAndSeekAcks++;
|
pendingSetSourceProviderAndSeekAcks++;
|
||||||
internalPlayer.seekTo(sourceIndex, position);
|
internalPlayer.seekTo(sourceIndex, positionMs * 1000);
|
||||||
for (EventListener listener : listeners) {
|
for (EventListener listener : listeners) {
|
||||||
listener.onPositionDiscontinuity(sourceIndex, position);
|
listener.onPositionDiscontinuity(sourceIndex, positionMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,28 +182,28 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
long durationUs = playbackInfo.durationUs;
|
long durationUs = playbackInfo.durationUs;
|
||||||
return durationUs == C.UNSET_TIME_US ? ExoPlayer.UNKNOWN_TIME : durationUs / 1000;
|
return durationUs == C.UNSET_TIME_US ? ExoPlayer.UNKNOWN_TIME : durationUs / 1000;
|
||||||
} else {
|
} else {
|
||||||
return duration;
|
return maskingDurationMs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentPosition() {
|
public long getCurrentPosition() {
|
||||||
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.positionUs / 1000 : position;
|
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.positionUs / 1000
|
||||||
|
: maskingPositionMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCurrentSourceIndex() {
|
public int getCurrentSourceIndex() {
|
||||||
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.sourceIndex : sourceIndex;
|
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.sourceIndex : maskingSourceIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getBufferedPosition() {
|
public long getBufferedPosition() {
|
||||||
if (pendingSetSourceProviderAndSeekAcks == 0) {
|
if (pendingSetSourceProviderAndSeekAcks == 0) {
|
||||||
long bufferedPositionUs = playbackInfo.bufferedPositionUs;
|
long bufferedPositionUs = playbackInfo.bufferedPositionUs;
|
||||||
return bufferedPositionUs == C.UNSET_TIME_US || bufferedPositionUs == C.END_OF_SOURCE_US
|
return bufferedPositionUs == C.END_OF_SOURCE_US ? getDuration() : bufferedPositionUs / 1000;
|
||||||
? ExoPlayer.UNKNOWN_TIME : bufferedPositionUs / 1000;
|
|
||||||
} else {
|
} else {
|
||||||
return position;
|
return maskingPositionMs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public PlaybackInfo(int sourceIndex) {
|
public PlaybackInfo(int sourceIndex) {
|
||||||
this.sourceIndex = sourceIndex;
|
this.sourceIndex = sourceIndex;
|
||||||
bufferedPositionUs = C.UNSET_TIME_US;
|
|
||||||
durationUs = C.UNSET_TIME_US;
|
durationUs = C.UNSET_TIME_US;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,8 +145,8 @@ import java.util.ArrayList;
|
||||||
handler.obtainMessage(MSG_SET_PLAY_WHEN_READY, playWhenReady ? 1 : 0, 0).sendToTarget();
|
handler.obtainMessage(MSG_SET_PLAY_WHEN_READY, playWhenReady ? 1 : 0, 0).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void seekTo(int sourceIndex, long positionMs) {
|
public void seekTo(int sourceIndex, long positionUs) {
|
||||||
handler.obtainMessage(MSG_SEEK_TO, sourceIndex, -1, positionMs).sendToTarget();
|
handler.obtainMessage(MSG_SEEK_TO, sourceIndex, -1, positionUs).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
|
@ -278,7 +277,6 @@ import java.util.ArrayList;
|
||||||
// TODO[playlists]: Take into account the buffered position in the timeline.
|
// TODO[playlists]: Take into account the buffered position in the timeline.
|
||||||
long minBufferDurationUs = rebuffering ? minRebufferUs : minBufferUs;
|
long minBufferDurationUs = rebuffering ? minRebufferUs : minBufferUs;
|
||||||
return minBufferDurationUs <= 0
|
return minBufferDurationUs <= 0
|
||||||
|| playbackInfo.bufferedPositionUs == C.UNSET_TIME_US
|
|
||||||
|| playbackInfo.bufferedPositionUs == C.END_OF_SOURCE_US
|
|| playbackInfo.bufferedPositionUs == C.END_OF_SOURCE_US
|
||||||
|| playbackInfo.bufferedPositionUs >= playbackInfo.positionUs + minBufferDurationUs
|
|| playbackInfo.bufferedPositionUs >= playbackInfo.positionUs + minBufferDurationUs
|
||||||
|| (playbackInfo.durationUs != C.UNSET_TIME_US
|
|| (playbackInfo.durationUs != C.UNSET_TIME_US
|
||||||
|
|
@ -433,11 +431,11 @@ import java.util.ArrayList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void seekToInternal(int sourceIndex, long seekPositionMs) throws ExoPlaybackException {
|
private void seekToInternal(int sourceIndex, long seekPositionUs) throws ExoPlaybackException {
|
||||||
try {
|
try {
|
||||||
if (sourceIndex == playbackInfo.sourceIndex
|
if (sourceIndex == playbackInfo.sourceIndex
|
||||||
&& seekPositionMs == (playbackInfo.positionUs / 1000)) {
|
&& (seekPositionUs / 1000) == (playbackInfo.positionUs / 1000)) {
|
||||||
// Seek is to the current position. Do nothing.
|
// Seek position equals the current position to the nearest millisecond. Do nothing.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -446,7 +444,6 @@ import java.util.ArrayList;
|
||||||
eventHandler.obtainMessage(MSG_SOURCE_CHANGED, playbackInfo).sendToTarget();
|
eventHandler.obtainMessage(MSG_SOURCE_CHANGED, playbackInfo).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
long seekPositionUs = seekPositionMs * 1000;
|
|
||||||
rebuffering = false;
|
rebuffering = false;
|
||||||
standaloneMediaClock.stop();
|
standaloneMediaClock.stop();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue