App crashes after clicking on setting before the content is loaded

Viewed 55

My app crashes or goes back to home screen when someone click twice on settings in exo player, 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;
      });

enter image description here

1 Answers

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;
Related