Skip to content

Commit

Permalink
Add reason to onPositionDiscontinuity.
Browse files Browse the repository at this point in the history
This allows listeners to easily determine the source of the discontinuity.
Reasons can be period transitions, seeks, and internal reasons.

Listeners still using the deprecated ExoPlayer.EventListener interface were
updated to Player.EventListener.

GitHub: #3252

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168549612
  • Loading branch information
tonihei authored and ojw28 committed Sep 15, 2017
1 parent 872cbec commit 7d59383
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}

@Override
public void onPositionDiscontinuity() {
Log.d(TAG, "positionDiscontinuity");
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
Log.d(TAG, "positionDiscontinuity [" + getDiscontinuityReasonString(reason) + "]");
}

@Override
Expand Down Expand Up @@ -484,4 +484,17 @@ private static String getRepeatModeString(@Player.RepeatMode int repeatMode) {
return "?";
}
}

private static String getDiscontinuityReasonString(@Player.DiscontinuityReason int reason) {
switch (reason) {
case Player.DISCONTINUITY_REASON_PERIOD_TRANSITION:
return "PERIOD_TRANSITION";
case Player.DISCONTINUITY_REASON_SEEK:
return "SEEK";
case Player.DISCONTINUITY_REASON_INTERNAL:
return "INTERNAL";
default:
return "?";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
if (inErrorState) {
// This will only occur if the user has performed a seek whilst in the error state. Update the
// resume position so that if the user then retries, playback will resume from the position to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void seekTo(int windowIndex, long positionMs) {
pendingSeekWindowIndex = windowIndex;
pendingSeekPositionMs = positionMs;
for (EventListener listener : listeners) {
listener.onPositionDiscontinuity();
listener.onPositionDiscontinuity(Player.DISCONTINUITY_REASON_SEEK);
}
}
}
Expand Down Expand Up @@ -539,7 +539,7 @@ public void updateInternalState() {
if (this.currentWindowIndex != currentWindowIndex) {
this.currentWindowIndex = currentWindowIndex;
for (EventListener listener : listeners) {
listener.onPositionDiscontinuity();
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_PERIOD_TRANSITION);
}
}
if (updateTracksAndSelections()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public void onPlayerError(ExoPlaybackException error) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
if (adsManager == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.DiscontinuityReason;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.TrackGroupArray;
Expand Down Expand Up @@ -278,7 +279,7 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@DiscontinuityReason int reason) {
Callback callback = getCallback();
callback.onCurrentPositionChanged(LeanbackPlayerAdapter.this);
callback.onBufferedPositionChanged(LeanbackPlayerAdapter.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public void onPlayerError(ExoPlaybackException error) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
if (currentWindowIndex != player.getCurrentWindowIndex()) {
if (queueNavigator != null) {
queueNavigator.onCurrentWindowIndexChanged(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void seekTo(int windowIndex, long positionMs) {
maskingWindowPositionMs = positionMs;
internalPlayer.seekTo(timeline, windowIndex, C.msToUs(positionMs));
for (Player.EventListener listener : listeners) {
listener.onPositionDiscontinuity();
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_SEEK);
}
}
}
Expand Down Expand Up @@ -484,7 +484,7 @@ public Object getCurrentManifest() {
}
if (msg.arg1 != 0) {
for (Player.EventListener listener : listeners) {
listener.onPositionDiscontinuity();
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_SEEK);
}
}
}
Expand All @@ -494,7 +494,7 @@ public Object getCurrentManifest() {
if (pendingSeekAcks == 0) {
playbackInfo = (ExoPlayerImplInternal.PlaybackInfo) msg.obj;
for (Player.EventListener listener : listeners) {
listener.onPositionDiscontinuity();
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_PERIOD_TRANSITION);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface EventListener {
* Note that if the timeline has changed then a position discontinuity may also have occurred.
* For example, the current period index may have changed as a result of periods being added or
* removed from the timeline. This will <em>not</em> be reported via a separate call to
* {@link #onPositionDiscontinuity()}.
* {@link #onPositionDiscontinuity(int)}.
*
* @param timeline The latest timeline. Never null, but may be empty.
* @param manifest The latest manifest. May be null.
Expand Down Expand Up @@ -119,8 +119,10 @@ interface EventListener {
* <p>
* When a position discontinuity occurs as a result of a change to the timeline this method is
* <em>not</em> called. {@link #onTimelineChanged(Timeline, Object)} is called in this case.
*
* @param reason The {@link DiscontinuityReason} responsible for the discontinuity.
*/
void onPositionDiscontinuity();
void onPositionDiscontinuity(@DiscontinuityReason int reason);

/**
* Called when the current playback parameters change. The playback parameters may change due to
Expand Down Expand Up @@ -172,6 +174,27 @@ interface EventListener {
*/
int REPEAT_MODE_ALL = 2;

/**
* Reasons for position discontinuities.
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK,
DISCONTINUITY_REASON_INTERNAL})
public @interface DiscontinuityReason {}
/**
* Automatic playback transition from one period in the timeline to the next. The period index may
* be the same as it was before the discontinuity in case the current period is repeated.
*/
int DISCONTINUITY_REASON_PERIOD_TRANSITION = 0;
/**
* Seek within the current period or to another period.
*/
int DISCONTINUITY_REASON_SEEK = 1;
/**
* Discontinuity introduced internally by the source.
*/
int DISCONTINUITY_REASON_INTERNAL = 2;

/**
* Register a listener to receive events from the player. The listener's methods will be called on
* the thread that was used to construct the player. However, if the thread used to construct the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
updateAndPost();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
updateNavigation();
updateProgress();
}
Expand Down Expand Up @@ -1150,4 +1150,3 @@ public void onClick(View view) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ public void onPlayerError(ExoPlaybackException e) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ protected void doActionAndScheduleNextImpl(final SimpleExoPlayer player,
final ActionNode nextAction) {
player.addListener(new PlayerListener() {
@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
player.removeListener(this);
nextAction.schedule(player, trackSelector, surface, handler);
}
Expand Down Expand Up @@ -445,7 +445,7 @@ public void onPlayerError(ExoPlaybackException error) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public final void onPlayerError(ExoPlaybackException error) {
}

@Override
public final void onPositionDiscontinuity() {
public final void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void onPlayerError(ExoPlaybackException error) {
}

@Override
public void onPositionDiscontinuity() {
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
positionDiscontinuityCount++;
periodIndices.add(player.getCurrentPeriodIndex());
}
Expand Down

0 comments on commit 7d59383

Please sign in to comment.