L
L
Lord Drous2016-11-16 20:15:15
Java
Lord Drous, 2016-11-16 20:15:15

When switching back to the fragment, an error occurs, how to fix it?

Hello, I have a stop button, when I click on play, then I click on stop, the radio broadcasting stops, but there is such a moment, once I accidentally clicked on stop 2 times and the application crashed, how can I handle the event so that when I click 2 nothing did not happen, below is the stop button listener code and the screen83fd1a5cf1844f86bccab4a98949a6c0.png

@Override
            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    mediaPlayer.stop();
                    mediaPlayer = null;
                    playPause.setChecked(false);
                }
                else {
                    playPause.setChecked(true);
                }
            }

Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Grichenko, 2016-11-16
@Kalobok

Correct the check:
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question