Skip to content

Commit

Permalink
Clean up position restoration logic in demo app
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148024082
  • Loading branch information
ojw28 committed Feb 23, 2017
1 parent 17762eb commit 55a3fca
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
private DefaultTrackSelector trackSelector;
private TrackSelectionHelper trackSelectionHelper;
private DebugTextViewHelper debugViewHelper;
private boolean playerNeedsSource;
private boolean needRetrySource;

private boolean shouldAutoPlay;
private int resumeWindow;
Expand Down Expand Up @@ -229,7 +229,8 @@ public void onVisibilityChange(int visibility) {

private void initializePlayer() {
Intent intent = getIntent();
if (player == null) {
boolean needNewPlayer = player == null;
if (needNewPlayer) {
boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false);
UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA)
? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
Expand Down Expand Up @@ -272,9 +273,8 @@ private void initializePlayer() {
player.setPlayWhenReady(shouldAutoPlay);
debugViewHelper = new DebugTextViewHelper(player, debugTextView);
debugViewHelper.start();
playerNeedsSource = true;
}
if (playerNeedsSource) {
if (needNewPlayer || needRetrySource) {
String action = intent.getAction();
Uri[] uris;
String[] extensions;
Expand Down Expand Up @@ -310,7 +310,7 @@ private void initializePlayer() {
player.seekTo(resumeWindow, resumePosition);
}
player.prepare(mediaSource, !haveResumePosition, false);
playerNeedsSource = false;
needRetrySource = false;
updateButtonVisibilities();
}
}
Expand Down Expand Up @@ -419,7 +419,7 @@ public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

@Override
public void onPositionDiscontinuity() {
if (playerNeedsSource) {
if (needRetrySource) {
// 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
// which they seeked.
Expand Down Expand Up @@ -460,7 +460,7 @@ public void onPlayerError(ExoPlaybackException e) {
if (errorString != null) {
showToast(errorString);
}
playerNeedsSource = true;
needRetrySource = true;
if (isBehindLiveWindow(e)) {
clearResumePosition();
initializePlayer();
Expand Down Expand Up @@ -492,7 +492,7 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
private void updateButtonVisibilities() {
debugRootView.removeAllViews();

retryButton.setVisibility(playerNeedsSource ? View.VISIBLE : View.GONE);
retryButton.setVisibility(needRetrySource ? View.VISIBLE : View.GONE);
debugRootView.addView(retryButton);

if (player == null) {
Expand Down

0 comments on commit 55a3fca

Please sign in to comment.