Home > OS >  App crashes after clicking on setting before the content is loaded
App crashes after clicking on setting before the content is loaded

Time:09-18

Update: This error has been solved, I had to put contentLoaded = True; somewhere else which solved the problem. Sorry for editing this post way too many times because i'm new to stackoverflow and getting used to posting and stuffs. thanks to whoever participated :)

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

This is where I put the code to solve that error:

 @Override
    public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
        if (playWhenReady && playbackState == Player.STATE_READY) {
            isPlaying = true;
            // Active playback.
            contentLoaded = true;
            progressBar.setVisibility(View.GONE);
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (!categoryType.equals("tv") && player != null) {
                        playerCurrentPosition = player.getCurrentPosition();
                        mediaDuration = player.getDuration();
                        updateContinueWatchingData();
                    }
                    handler.postDelayed(this, 1000);
                }
            }, 1000);
        } else if (playbackState == Player.STATE_READY) {
            progressBar.setVisibility(View.GONE);
            isPlaying = false;
        } else if (playbackState == Player.STATE_BUFFERING) {
            isPlaying = false;
            progressBar.setVisibility(VISIBLE);
        } else if (playbackState == Player.STATE_ENDED) {
            //---delete into continueWatching------
            ContinueWatchingModel model = new ContinueWatchingModel(id, title,
                    castImageUrl, 0, 0, mediaUrl,
                    categoryType, serverType);
            viewModel.delete(model);

        } else {
            // player paused in any state
            isPlaying = false;
            playerCurrentPosition = player.getCurrentPosition();
            mediaDuration = player.getDuration();
        }
    }

CodePudding user response:

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