Fix playing local content after permission granted.
After maybeRequestReadExternalStoragePermission and the subsequent granting of the permission, the media source would never be created. I can't see a case where initializePlayer shouldn't create a new MediaSource, so I've just removed the condition. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164260074
This commit is contained in:
parent
576f362912
commit
c28ebf10f7
@ -119,7 +119,7 @@ public class PlayerActivity extends Activity implements OnClickListener, EventLi
|
|||||||
private DefaultTrackSelector trackSelector;
|
private DefaultTrackSelector trackSelector;
|
||||||
private TrackSelectionHelper trackSelectionHelper;
|
private TrackSelectionHelper trackSelectionHelper;
|
||||||
private DebugTextViewHelper debugViewHelper;
|
private DebugTextViewHelper debugViewHelper;
|
||||||
private boolean needRetrySource;
|
private boolean inErrorState;
|
||||||
private TrackGroupArray lastSeenTrackGroupArray;
|
private TrackGroupArray lastSeenTrackGroupArray;
|
||||||
|
|
||||||
private boolean shouldAutoPlay;
|
private boolean shouldAutoPlay;
|
||||||
@ -297,60 +297,58 @@ public class PlayerActivity extends Activity implements OnClickListener, EventLi
|
|||||||
debugViewHelper = new DebugTextViewHelper(player, debugTextView);
|
debugViewHelper = new DebugTextViewHelper(player, debugTextView);
|
||||||
debugViewHelper.start();
|
debugViewHelper.start();
|
||||||
}
|
}
|
||||||
if (needNewPlayer || needRetrySource) {
|
String action = intent.getAction();
|
||||||
String action = intent.getAction();
|
Uri[] uris;
|
||||||
Uri[] uris;
|
String[] extensions;
|
||||||
String[] extensions;
|
if (ACTION_VIEW.equals(action)) {
|
||||||
if (ACTION_VIEW.equals(action)) {
|
uris = new Uri[]{intent.getData()};
|
||||||
uris = new Uri[] {intent.getData()};
|
extensions = new String[]{intent.getStringExtra(EXTENSION_EXTRA)};
|
||||||
extensions = new String[] {intent.getStringExtra(EXTENSION_EXTRA)};
|
} else if (ACTION_VIEW_LIST.equals(action)) {
|
||||||
} else if (ACTION_VIEW_LIST.equals(action)) {
|
String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA);
|
||||||
String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA);
|
uris = new Uri[uriStrings.length];
|
||||||
uris = new Uri[uriStrings.length];
|
for (int i = 0; i < uriStrings.length; i++) {
|
||||||
for (int i = 0; i < uriStrings.length; i++) {
|
uris[i] = Uri.parse(uriStrings[i]);
|
||||||
uris[i] = Uri.parse(uriStrings[i]);
|
|
||||||
}
|
|
||||||
extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA);
|
|
||||||
if (extensions == null) {
|
|
||||||
extensions = new String[uriStrings.length];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showToast(getString(R.string.unexpected_intent_action, action));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (Util.maybeRequestReadExternalStoragePermission(this, uris)) {
|
extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA);
|
||||||
// The player will be reinitialized if the permission is granted.
|
if (extensions == null) {
|
||||||
return;
|
extensions = new String[uriStrings.length];
|
||||||
}
|
}
|
||||||
MediaSource[] mediaSources = new MediaSource[uris.length];
|
} else {
|
||||||
for (int i = 0; i < uris.length; i++) {
|
showToast(getString(R.string.unexpected_intent_action, action));
|
||||||
mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
|
return;
|
||||||
}
|
|
||||||
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
|
|
||||||
: new ConcatenatingMediaSource(mediaSources);
|
|
||||||
String adTagUriString = intent.getStringExtra(AD_TAG_URI_EXTRA);
|
|
||||||
if (adTagUriString != null) {
|
|
||||||
Uri adTagUri = Uri.parse(adTagUriString);
|
|
||||||
if (!adTagUri.equals(loadedAdTagUri)) {
|
|
||||||
releaseAdsLoader();
|
|
||||||
loadedAdTagUri = adTagUri;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
mediaSource = createAdsMediaSource(mediaSource, Uri.parse(adTagUriString));
|
|
||||||
} catch (Exception e) {
|
|
||||||
showToast(R.string.ima_not_loaded);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
releaseAdsLoader();
|
|
||||||
}
|
|
||||||
boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
|
|
||||||
if (haveResumePosition) {
|
|
||||||
player.seekTo(resumeWindow, resumePosition);
|
|
||||||
}
|
|
||||||
player.prepare(mediaSource, !haveResumePosition, false);
|
|
||||||
needRetrySource = false;
|
|
||||||
updateButtonVisibilities();
|
|
||||||
}
|
}
|
||||||
|
if (Util.maybeRequestReadExternalStoragePermission(this, uris)) {
|
||||||
|
// The player will be reinitialized if the permission is granted.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MediaSource[] mediaSources = new MediaSource[uris.length];
|
||||||
|
for (int i = 0; i < uris.length; i++) {
|
||||||
|
mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
|
||||||
|
}
|
||||||
|
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
|
||||||
|
: new ConcatenatingMediaSource(mediaSources);
|
||||||
|
String adTagUriString = intent.getStringExtra(AD_TAG_URI_EXTRA);
|
||||||
|
if (adTagUriString != null) {
|
||||||
|
Uri adTagUri = Uri.parse(adTagUriString);
|
||||||
|
if (!adTagUri.equals(loadedAdTagUri)) {
|
||||||
|
releaseAdsLoader();
|
||||||
|
loadedAdTagUri = adTagUri;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mediaSource = createAdsMediaSource(mediaSource, Uri.parse(adTagUriString));
|
||||||
|
} catch (Exception e) {
|
||||||
|
showToast(R.string.ima_not_loaded);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
releaseAdsLoader();
|
||||||
|
}
|
||||||
|
boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
|
||||||
|
if (haveResumePosition) {
|
||||||
|
player.seekTo(resumeWindow, resumePosition);
|
||||||
|
}
|
||||||
|
player.prepare(mediaSource, !haveResumePosition, false);
|
||||||
|
inErrorState = false;
|
||||||
|
updateButtonVisibilities();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
|
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
|
||||||
@ -502,7 +500,7 @@ public class PlayerActivity extends Activity implements OnClickListener, EventLi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPositionDiscontinuity() {
|
public void onPositionDiscontinuity() {
|
||||||
if (needRetrySource) {
|
if (inErrorState) {
|
||||||
// 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.
|
||||||
@ -548,7 +546,7 @@ public class PlayerActivity extends Activity implements OnClickListener, EventLi
|
|||||||
if (errorString != null) {
|
if (errorString != null) {
|
||||||
showToast(errorString);
|
showToast(errorString);
|
||||||
}
|
}
|
||||||
needRetrySource = true;
|
inErrorState = true;
|
||||||
if (isBehindLiveWindow(e)) {
|
if (isBehindLiveWindow(e)) {
|
||||||
clearResumePosition();
|
clearResumePosition();
|
||||||
initializePlayer();
|
initializePlayer();
|
||||||
@ -584,7 +582,7 @@ public class PlayerActivity extends Activity implements OnClickListener, EventLi
|
|||||||
private void updateButtonVisibilities() {
|
private void updateButtonVisibilities() {
|
||||||
debugRootView.removeAllViews();
|
debugRootView.removeAllViews();
|
||||||
|
|
||||||
retryButton.setVisibility(needRetrySource ? View.VISIBLE : View.GONE);
|
retryButton.setVisibility(inErrorState ? View.VISIBLE : View.GONE);
|
||||||
debugRootView.addView(retryButton);
|
debugRootView.addView(retryButton);
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user