Issue
My app crashes or goes back to home screen when someone click on settings in exo player twice, pressing it once shows " Please wait for the content to load " toast but pressing it twice crashes the app, although after the content is loaded the app doesn't crash, you can click on it as many times as you want. how do I solve it?
ImageView img_audio = findViewById(R.id.img_audio);
img_audio.setOnClickListener(view -> {
if (contentLoaded) {
MappingTrackSelector.MappedTrackInfo mappedTrackInfo;
DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
TrackSelectionDialog trackSelectionDialog =
TrackSelectionDialog.createForTrackSelector(
trackSelector,
/* onDismissListener= */ dismissedDialog -> {
});
trackSelectionDialog.show(getSupportFragmentManager(), null);
} else {
Toast.makeText(DetailsActivity.this, R.string.please_wait, Toast.LENGTH_LONG).show();
}
// Active playback.
contentLoaded = true;
});
Solution
Probably from setting the condition to true, on the first click. Then on the second click, it tries to access the content, which is not loaded. Or why is the content for sure loaded, when the event was fired once?
// Active playback.
contentLoaded = true;
Answered By - ILikeTrains
Answer Checked By - Clifford M. (JavaFixing Volunteer)