Home > database >  How to check MediaPlayer is ready to call start() | Android Kotlin
How to check MediaPlayer is ready to call start() | Android Kotlin

Time:06-04

I want to check if the prepare() is finished to call start(),Because I sometime when I press the start button it starts playing but I can't pause or stop the player.

Now: I need to wait for a while to make sure that prepare() is finished and it is ready to start and then press start button.

Any suggestions?

CodePudding user response:

Set OnPreparedListener to the media player instance and inside onPrepared() start the media player.

player.setOnPreparedListener(new OnPreparedListener() {
                
                @Override
                public void onPrepared(MediaPlayer mp) {
                    player.start();
                
                }
            });

developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener

  • Related