0

I decided to deal with the mediaplayer android. The question arose as to how I could track when the track being played ended. I'm not entirely happy with what the mediaplayer does after the end of the track. I would like to do a reset of the mediaplayer myself after the playback ends. Can I do it somehow?

If necessary, here's my code:

public void play(View v){

    String music = "m"+"s"+stroknam;
    if (player == null) {
        try {
            player = MediaPlayer.create(this, getResources().getIdentifier(music, "raw", "com."));
        }
        catch (Exception e) {
            e.printStackTrace();
            Toast toast = Toast.makeText(this, "Скоро в приложении!", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM, 0,160);
            toast.show();
            return;
        }
    }
    player.start();
}
public void pause(View v){
    if (player != null) {
        player.pause();
    }
}
public void stop(View v){
    stopPlayer();
}
private void stopPlayer(){
    if (player != null){
        player.release();
        player = null;
    }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135

0 Answers0