Commit 55a3fca6 by olly Committed by Oliver Woodman

Clean up position restoration logic in demo app

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148024082
parent 17762eba
...@@ -110,7 +110,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -110,7 +110,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
private DefaultTrackSelector trackSelector; private DefaultTrackSelector trackSelector;
private TrackSelectionHelper trackSelectionHelper; private TrackSelectionHelper trackSelectionHelper;
private DebugTextViewHelper debugViewHelper; private DebugTextViewHelper debugViewHelper;
private boolean playerNeedsSource; private boolean needRetrySource;
private boolean shouldAutoPlay; private boolean shouldAutoPlay;
private int resumeWindow; private int resumeWindow;
...@@ -229,7 +229,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -229,7 +229,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
private void initializePlayer() { private void initializePlayer() {
Intent intent = getIntent(); Intent intent = getIntent();
if (player == null) { boolean needNewPlayer = player == null;
if (needNewPlayer) {
boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false); boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false);
UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA)
? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null; ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
...@@ -272,9 +273,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -272,9 +273,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
player.setPlayWhenReady(shouldAutoPlay); player.setPlayWhenReady(shouldAutoPlay);
debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper = new DebugTextViewHelper(player, debugTextView);
debugViewHelper.start(); debugViewHelper.start();
playerNeedsSource = true;
} }
if (playerNeedsSource) { if (needNewPlayer || needRetrySource) {
String action = intent.getAction(); String action = intent.getAction();
Uri[] uris; Uri[] uris;
String[] extensions; String[] extensions;
...@@ -310,7 +310,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -310,7 +310,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
player.seekTo(resumeWindow, resumePosition); player.seekTo(resumeWindow, resumePosition);
} }
player.prepare(mediaSource, !haveResumePosition, false); player.prepare(mediaSource, !haveResumePosition, false);
playerNeedsSource = false; needRetrySource = false;
updateButtonVisibilities(); updateButtonVisibilities();
} }
} }
...@@ -419,7 +419,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -419,7 +419,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
@Override @Override
public void onPositionDiscontinuity() { 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 // 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 // resume position so that if the user then retries, playback will resume from the position to
// which they seeked. // which they seeked.
...@@ -460,7 +460,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -460,7 +460,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
if (errorString != null) { if (errorString != null) {
showToast(errorString); showToast(errorString);
} }
playerNeedsSource = true; needRetrySource = true;
if (isBehindLiveWindow(e)) { if (isBehindLiveWindow(e)) {
clearResumePosition(); clearResumePosition();
initializePlayer(); initializePlayer();
...@@ -492,7 +492,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -492,7 +492,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
private void updateButtonVisibilities() { private void updateButtonVisibilities() {
debugRootView.removeAllViews(); debugRootView.removeAllViews();
retryButton.setVisibility(playerNeedsSource ? View.VISIBLE : View.GONE); retryButton.setVisibility(needRetrySource ? View.VISIBLE : View.GONE);
debugRootView.addView(retryButton); debugRootView.addView(retryButton);
if (player == null) { if (player == null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment