mirror of
https://github.com/samsonjs/media.git
synced 2026-04-15 12:55:46 +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;
|
||||
|
||||
import com.google.android.exoplayer.ExoPlayerImplInternal.PlaybackInfo;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
|
@ -42,12 +43,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
private int pendingSetSourceProviderAndSeekAcks;
|
||||
|
||||
// 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.
|
||||
private int sourceIndex;
|
||||
private long position;
|
||||
private long duration;
|
||||
private int maskingSourceIndex;
|
||||
private long maskingPositionMs;
|
||||
private long maskingDurationMs;
|
||||
|
||||
/**
|
||||
* 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
|
||||
public void setSourceProvider(SampleSourceProvider sourceProvider) {
|
||||
duration = ExoPlayer.UNKNOWN_TIME;
|
||||
position = 0;
|
||||
sourceIndex = 0;
|
||||
maskingSourceIndex = 0;
|
||||
maskingPositionMs = 0;
|
||||
maskingDurationMs = ExoPlayer.UNKNOWN_TIME;
|
||||
|
||||
pendingSetSourceProviderAndSeekAcks++;
|
||||
internalPlayer.setSourceProvider(sourceProvider);
|
||||
for (EventListener listener : listeners) {
|
||||
listener.onPositionDiscontinuity(sourceIndex, position);
|
||||
listener.onPositionDiscontinuity(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,14 +143,15 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
|
||||
@Override
|
||||
public void seekTo(int sourceIndex, long positionMs) {
|
||||
duration = sourceIndex == getCurrentSourceIndex() ? getDuration() : ExoPlayer.UNKNOWN_TIME;
|
||||
position = positionMs;
|
||||
this.sourceIndex = sourceIndex;
|
||||
boolean sourceChanging = sourceIndex != getCurrentSourceIndex();
|
||||
maskingSourceIndex = sourceIndex;
|
||||
maskingPositionMs = positionMs;
|
||||
maskingDurationMs = sourceChanging ? ExoPlayer.UNKNOWN_TIME : getDuration();
|
||||
|
||||
pendingSetSourceProviderAndSeekAcks++;
|
||||
internalPlayer.seekTo(sourceIndex, position);
|
||||
internalPlayer.seekTo(sourceIndex, positionMs * 1000);
|
||||
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;
|
||||
return durationUs == C.UNSET_TIME_US ? ExoPlayer.UNKNOWN_TIME : durationUs / 1000;
|
||||
} else {
|
||||
return duration;
|
||||
return maskingDurationMs;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentPosition() {
|
||||
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.positionUs / 1000 : position;
|
||||
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.positionUs / 1000
|
||||
: maskingPositionMs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentSourceIndex() {
|
||||
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.sourceIndex : sourceIndex;
|
||||
return pendingSetSourceProviderAndSeekAcks == 0 ? playbackInfo.sourceIndex : maskingSourceIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBufferedPosition() {
|
||||
if (pendingSetSourceProviderAndSeekAcks == 0) {
|
||||
long bufferedPositionUs = playbackInfo.bufferedPositionUs;
|
||||
return bufferedPositionUs == C.UNSET_TIME_US || bufferedPositionUs == C.END_OF_SOURCE_US
|
||||
? ExoPlayer.UNKNOWN_TIME : bufferedPositionUs / 1000;
|
||||
return bufferedPositionUs == C.END_OF_SOURCE_US ? getDuration() : bufferedPositionUs / 1000;
|
||||
} else {
|
||||
return position;
|
||||
return maskingPositionMs;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ import java.util.ArrayList;
|
|||
|
||||
public PlaybackInfo(int sourceIndex) {
|
||||
this.sourceIndex = sourceIndex;
|
||||
bufferedPositionUs = 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();
|
||||
}
|
||||
|
||||
public void seekTo(int sourceIndex, long positionMs) {
|
||||
handler.obtainMessage(MSG_SEEK_TO, sourceIndex, -1, positionMs).sendToTarget();
|
||||
public void seekTo(int sourceIndex, long positionUs) {
|
||||
handler.obtainMessage(MSG_SEEK_TO, sourceIndex, -1, positionUs).sendToTarget();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
|
@ -278,7 +277,6 @@ import java.util.ArrayList;
|
|||
// TODO[playlists]: Take into account the buffered position in the timeline.
|
||||
long minBufferDurationUs = rebuffering ? minRebufferUs : minBufferUs;
|
||||
return minBufferDurationUs <= 0
|
||||
|| playbackInfo.bufferedPositionUs == C.UNSET_TIME_US
|
||||
|| playbackInfo.bufferedPositionUs == C.END_OF_SOURCE_US
|
||||
|| playbackInfo.bufferedPositionUs >= playbackInfo.positionUs + minBufferDurationUs
|
||||
|| (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 {
|
||||
if (sourceIndex == playbackInfo.sourceIndex
|
||||
&& seekPositionMs == (playbackInfo.positionUs / 1000)) {
|
||||
// Seek is to the current position. Do nothing.
|
||||
&& (seekPositionUs / 1000) == (playbackInfo.positionUs / 1000)) {
|
||||
// Seek position equals the current position to the nearest millisecond. Do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -446,7 +444,6 @@ import java.util.ArrayList;
|
|||
eventHandler.obtainMessage(MSG_SOURCE_CHANGED, playbackInfo).sendToTarget();
|
||||
}
|
||||
|
||||
long seekPositionUs = seekPositionMs * 1000;
|
||||
rebuffering = false;
|
||||
standaloneMediaClock.stop();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue