Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaPlayer is not looping

I want to create activity background music, but MediaPlayer playing not repeatedly :( Why my MediaPlayer is not looping?

There is my code:

MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.tersetetete);

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setVolume(8f, 8f);
    mediaPlayer.setLooping(true);

    mediaPlayer = MediaPlayer.create(this, R.raw.fon);
    mediaPlayer.start();
}
like image 274
Amon Olimov Avatar asked Dec 16 '22 10:12

Amon Olimov


1 Answers

call

 mediaPlayer.setLooping(true);

after

    mediaPlayer.start(); 
like image 127
stinepike Avatar answered Dec 27 '22 09:12

stinepike